Created
June 7, 2014 07:01
-
-
Save alfanick/730212f9d0b89b2420ca to your computer and use it in GitHub Desktop.
Apple Grand Central Dispatch (GCD) in Swift
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
import Foundation | |
func async(block: () -> (), priority: Int = DISPATCH_QUEUE_PRIORITY_DEFAULT) { | |
dispatch_async(dispatch_get_global_queue(priority, 0), block) | |
} | |
func par(count: UInt, block: (UInt) -> (), priority: Int = DISPATCH_QUEUE_PRIORITY_DEFAULT) { | |
dispatch_apply(count, dispatch_get_global_queue(priority, 0), block) | |
} | |
async { | |
println("foo") | |
} | |
par(20) { | |
println("\($0)") | |
} | |
sleep(1) | |
println("Got it!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any idea why par(20) isn't producing a list of values between 0 and 19?