Created
November 17, 2020 12:05
-
-
Save sayler8182/77a5a2b7c2e53b1b46c654821be7013e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var item: DispatchWorkItem! | |
item = DispatchWorkItem { | |
sleep(2) | |
guard !item.isCancelled else { | |
print("Work has been cancelled") | |
return | |
} | |
print("Work has been done") | |
} | |
DispatchQueue.global().async(execute: item) | |
DispatchQueue.global().async { | |
sleep(1) | |
item.cancel() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment