Skip to content

Instantly share code, notes, and snippets.

@shoheiyokoyama
Last active August 15, 2023 17:33
Show Gist options
  • Save shoheiyokoyama/64c047fc39e59211d9a0cda4a4d803cd to your computer and use it in GitHub Desktop.
Save shoheiyokoyama/64c047fc39e59211d9a0cda4a4d803cd to your computer and use it in GitHub Desktop.
DispatchWorkItem cancel()
let queue = DispatchQueue(label: "queue", attributes: .concurrent)
let workItem = DispatchWorkItem {
print("done")
}
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
queue.async(execute: workItem) // not work
}
workItem.cancel()
@joice-g
Copy link

joice-g commented Jan 31, 2023

does workItem.cancel() cancels the current item which is executing currently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment