Skip to content

Instantly share code, notes, and snippets.

@ivarvong
Created December 21, 2014 19:18
Show Gist options
  • Save ivarvong/88ae930c440262f63b93 to your computer and use it in GitHub Desktop.
Save ivarvong/88ae930c440262f63b93 to your computer and use it in GitHub Desktop.
def pmap(items)
queue = Queue.new
threads = items.map do |item|
Thread.new do
queue.push yield(item)
end
end
threads.map &:join
output = []
output << queue.pop until queue.empty?
output
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment