Dispatch Groups

Sometimes you want to fan some work out to a number of different queues and then wait until everything completes. For instance, rendering a page in a server might involve hitting a database, running the text through a rendering engine, and appending any insightful and relevant comments that have been left on the page.

A dispatch group is a collection of blocks that have been dispatched onto queues asynchronously. To create a group to track the collection of blocks, you use

dispatch_group_t dispatch_group_create (void);

Rather than dispatching directly onto other queues, you would use dispatch_group_async() to put the block onto a queue, but you also add the work item to the work group.

void dispatch_group_async (dispatch_group_t ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.