Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jayz5
Created September 4, 2018 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayz5/1b47b8a44816e4bfcc146e24da74b621 to your computer and use it in GitHub Desktop.
Save jayz5/1b47b8a44816e4bfcc146e24da74b621 to your computer and use it in GitHub Desktop.
import Foundation
var dwi: DispatchWorkItem? = nil
dwi = DispatchWorkItem {
print("in dispatch work item")
for i in 0..<1000 {
if dwi!.isCancelled { break }
print("dispatch item \(i)")
usleep(500000)
}
}
// submit the DWI to a concurrent queue
DispatchQueue.global().async(execute: dwi!)
// sleep() on the main thread
sleep(3)
print("we're done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment