Skip to content

Instantly share code, notes, and snippets.

@alfanick
Created June 7, 2014 07:01
Show Gist options
  • Save alfanick/730212f9d0b89b2420ca to your computer and use it in GitHub Desktop.
Save alfanick/730212f9d0b89b2420ca to your computer and use it in GitHub Desktop.
Apple Grand Central Dispatch (GCD) in Swift
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!")
Copy link

ghost commented Jul 27, 2014

Any idea why par(20) isn't producing a list of values between 0 and 19?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment