Skip to content

Instantly share code, notes, and snippets.

@svetlanama
Created October 18, 2018 00:02
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 svetlanama/72ce05243a7f694c6404e3a8f03617d1 to your computer and use it in GitHub Desktop.
Save svetlanama/72ce05243a7f694c6404e3a8f03617d1 to your computer and use it in GitHub Desktop.
OperationQueue
var testQueue: OperationQueue = {
var queue = OperationQueue()
queue.name = "Test queue"
queue.maxConcurrentOperationCount = 1
return queue
}()
for i in 0...200 {
let op = { print("xx: ", i);
sleep(5)
if i * 2 == 4 {
testQueue.cancelAllOperations()
}
}
testQueue.addOperation(op)
}
testQueue.waitUntilAllOperationsAreFinished()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment