Wait for all Operations in queue to finish before performing task

前端 未结 6 1861
小鲜肉
小鲜肉 2021-01-02 07:29

I have an Operation subclass and Operation queue with maxConcurrentOperationCount = 1.

This performs my operations in a sequential order that i add them which is goo

6条回答
  •  -上瘾入骨i
    2021-01-02 07:47

    I use the next solution:

    private let queue = OperationQueue()
    
    private func addOperations(_ operations: [Operation], completionHandler: @escaping () -> ()) {
        DispatchQueue.global().async { [unowned self] in
            self.queue.addOperations(operations, waitUntilFinished: true)
            DispatchQueue.main.async(execute: completionHandler)
        }
    }
    

提交回复
热议问题