Function

dispatch_group_wait

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

Declaration

long dispatch_group_wait(dispatch_group_t group, dispatch_time_t timeout);

Parameters

group

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

timeout

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).

Discussion

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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software