Created
October 18, 2018 00:02
-
-
Save svetlanama/72ce05243a7f694c6404e3a8f03617d1 to your computer and use it in GitHub Desktop.
OperationQueue
This file contains hidden or 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 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