Waits synchronously for the previously submitted block objects to finish; returns if the blocks do not complete before the specified timeout period has elapsed.


long dispatch_group_wait(dispatch_group_t group, dispatch_time_t timeout);



The dispatch group to wait on. This parameter cannot be NULL.


When to timeout (see dispatch_time). The DISPATCH_TIME_NOW and DISPATCH_TIME_FOREVER constants are provided as a convenience.

Return Value

Returns zero on success (all blocks associated with the group completed before the specified timeout) or non-zero on error (timeout occurred).


This function waits for the completion of the blocks associated with the given dispatch group and returns when either all blocks have completed or the specified timeout has elapsed. When a timeout occurs, the group is restored to its original state.

This function returns immediately if the dispatch group is empty (there are no blocks associated with the group).

After the successful return of this function, the dispatch group is empty, and can be reused for additional blocks. See dispatch_group_async for more information.

If your app isn’t using ARC, you should call dispatch_release on a dispatch group when it’s no longer needed.