Both dispatch queue and operation queue in Grand Central Dispatch (GCD) are available for ios development for handling asynchronous operation, and each has its own features.
Operation queue is a higher level API than dispatch queue, it is based on objective-c, so it is ARC ready. It only supports concurrent operation, although with addDependency method, it can define the dependency between operations and make them happen sequentially. It also supports operation priority, so a new operation with high priority may run before other operation added earlier in the queue. An completion block can be used to do some work which is not part of operation task.
Dispatch queue is based on c API, it supports block for task. It supports both concurrent queue and serial queue (private dispatch queue), and Main dispatch queue. Dispatch queue does not provide method to get queued item count or cancel queued item. If it is required to cancel all queued item in serial queue, one option is adding a sync item with empty completion block, if is called, then we know all previous items have been processed.
Operation queue is a higher level API than dispatch queue, it is based on objective-c, so it is ARC ready. It only supports concurrent operation, although with addDependency method, it can define the dependency between operations and make them happen sequentially. It also supports operation priority, so a new operation with high priority may run before other operation added earlier in the queue. An completion block can be used to do some work which is not part of operation task.
Dispatch queue is based on c API, it supports block for task. It supports both concurrent queue and serial queue (private dispatch queue), and Main dispatch queue. Dispatch queue does not provide method to get queued item count or cancel queued item. If it is required to cancel all queued item in serial queue, one option is adding a sync item with empty completion block, if is called, then we know all previous items have been processed.
No comments:
Post a Comment