I'm learning about Apple's GCD, and watching the video Concurrent Programming With GCD in Swift 3.
At 16:00 in this video, a flag for DispatchWorkItem
is described called .wait
, and the functionality and diagram both show exactly what I thought myQueue.sync(execute:)
was for.
So, my question is; what is the difference between:
myQueue.sync { sleep(1); print("sync") }
And:
myQueue.async(flags: .wait) { sleep(1); print("wait") }
// NOTE: This syntax doesn't compile, I'm not sure where the `.wait` flag moved to.
// `.wait` Seems not to be in the DispatchWorkItemFlags enum.
Seems like both approaches block the current thread while they wait for the named queue to:
- Finish any current or prior work (if serial)
- Complete the given block/work item
My understanding of this must be off somewhere, what am I missing?