How to do multithreading, concurrency or parallelism in iOS Swift?

后端 未结 4 1078
梦毁少年i
梦毁少年i 2021-01-30 11:07

Is there any way to create a worker thread in Swift?, for example, if there\'s a major functionality that requires a lot of calculations and hence causes the main thread to dela

4条回答
  •  一个人的身影
    2021-01-30 11:26

    This library lets you describe concurrency in a super expressive way:

    func handleError(_ error) { ... }
    
    HoneyBee.start(on: DispatchQueue.main) { root in
        root.setErrorHandler(handleError)
            .chain(function1) // runs on main queue
            .setBlockPerformer(DispatchQueue.global())
            .chain(function2) // runs on background queue
            .branch { stem in
                stem.chain(func3) // runs in parallel with func4
                +
                stem.chain(func4) // runs in parallel with func3
            }
            .chain(func5) // runs after func3 and func4 have finished
            .setBlockPerformer(DispatchQueue.main)
            .chain(updateUIFunc)
    }
    

提交回复
热议问题