Waits synchronously until execution of the specified dispatch block has completed or until the specified timeout has elapsed.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
Returns zero if the dispatch block completed within the specified timeout, or non-zero if the block timed out.
This function returns immediately if execution of the block object has already completed.
It is not possible to wait for multiple executions of the same block object with this interface. Instead, use
dispatch for that purpose.
A single dispatch block may either be waited on once and executed once, or it may be executed any number of times. The behavior of any other combination is undefined. Submission to a dispatch queue counts as an execution, even if cancellation using the
dispatch function means the block's code never runs.
The result of calling this function from multiple threads simultaneously with the same dispatch block is undefined, but note that doing so would violate the rules described in the previous paragraph.
If this function returns indicating that the specified timeout has elapsed, then that invocation does not count as the one allowed wait.
If at the time this function is called, the specified dispatch block has been submitted directly to a serial queue, the system makes a best effort to apply the necessary QoS overrides to ensure that the block and any blocks submitted earlier to that serial queue are executed at the QoS class (or higher) of the thread calling