---
title: dispatch_group_wait
framework: dispatch
role: symbol
role_heading: Function
path: dispatch/dispatch_group_wait
---

# 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

```occ
extern intptr_t 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 doc://com.apple.dispatch/documentation/Dispatch/dispatch_time). The doc://com.apple.dispatch/documentation/Dispatch/DISPATCH_TIME_NOW and doc://com.apple.dispatch/documentation/Dispatch/DISPATCH_TIME_FOREVER constants are provided as a convenience.

## Return Value

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

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.
