Created
August 28, 2014 01:08
-
-
Save chriseidhof/c62e45554c2394bb6871 to your computer and use it in GitHub Desktop.
GCD Wrappers
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
import Foundation | |
// Executes an array of blocks in parallel, but only returns after they're all done. | |
func parallel(blocks: [() -> ()]) { | |
let group = dispatch_group_create() | |
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) | |
for block in blocks { | |
dispatch_group_async(group, queue, block) | |
} | |
dispatch_group_wait(group, DISPATCH_TIME_FOREVER) | |
} | |
parallel(Array(1..<10).map { num in { print(num) } }) | |
println("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You only need to 'import Dispatch', instead of the whole Foundation.