sync(execute:)
Submits a block for synchronous execution on this queue.
- iOS
- 8.0+
- macOS
- 10.10+
func sync(execute workItem: DispatchWorkItem)
Parameters
- execute
The work item to be invoked on the queue.
Submits a work item to a dispatch queue like async(execute:)
, however sync(execute:)
will not return until the work item has finished.
Work items submitted to a queue with sync(execute:)
do not observe certain queue attributes of that queue when invoked (such as autorelease frequency and QoS class).
Calls to sync(execute:)
targeting the current queue will result in deadlock. Use of sync(execute:)
is also subject to the same multi-party deadlock problems that may result from the use of a mutex. Use of async(execute:)
is preferred.
As an optimization, sync(execute:)
invokes the work item on the thread which submitted it, except when the queue is the main queue or a queue targetting it.