Skip to content

Instantly share code, notes, and snippets.

@vialyx
Last active November 15, 2018 19:29
Show Gist options
  • Save vialyx/680a20c0e66bc11423263be1be62a781 to your computer and use it in GitHub Desktop.
Save vialyx/680a20c0e66bc11423263be1be62a781 to your computer and use it in GitHub Desktop.
let workItemFirst = DispatchWorkItem {
print("exec 1st WI")
// 2
}
let workItemSecond = DispatchWorkItem {
print("exec 1st WI")
// Not called
}
let queue = DispatchQueue(label: "queue")
queue.async(execute: workItemFirst)
queue.async(execute: workItemSecond)
// Cancel second item
workItemSecond.cancel()
print("main exec")
// 1
/* console output
main exec
exec 1st WI
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment