Created
March 12, 2015 15:46
-
-
Save asterite/40cf125b8ff6aaf95ac4 to your computer and use it in GitHub Desktop.
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
module Enumerable | |
def parallel_map(&block : T -> U) | |
channel = Channel(U).new(20) | |
count = 0 | |
each do |e| | |
spawn parallel_map_task(channel, block, e) | |
count += 1 | |
end | |
Array(U).new(count) { channel.receive } | |
end | |
private def parallel_map_task(channel, block, element) | |
channel.send block.call(element) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment