开发者

Reorder NSOperationQueue

I'm looking for a way to reorder an NSOperationQueue.

I could cancel all the operations and toss them back in using the order I want, but开发者_如何学JAVA I was hoping for something a little bit cleaner. Any thoughts?


The major difference between NSOperationQueue and the underlying GCD queues is that NSOperations support dependencies between operations. NSOperationQueue will not schedule an operation until all of its dependencies have completed. Of the available operations, the highest priority operation is chosen to run next.

Since the operation queue may run several operations simultaneously (according to maxConcurrentOperations), there is not strict sense of order on the queue. You would be much better off using the dependencies API or changing operation prorities.

I believe that you can change dependencies and priorities after adding an operation to the queue.


There is no ability to re-order operations in a queue. If you need to express that one operation must come after another, use the dependencies API to do so.

See the NSOperationQueue documentation for more information. The first two paragraphs of the overview discuss dependencies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜