Created
November 2, 2012 13:58
-
-
Save jwo/4001510 to your computer and use it in GitHub Desktop.
Celluloid simplistic example
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
require 'celluloid' | |
module Enumerable | |
def pmap(&block) | |
futures = map { |elem| Celluloid::Future.new(elem, &block) } | |
futures.map { |future| future.value } | |
end | |
end | |
puts "let's do this without celluloid!" | |
(1..10).map do |i| | |
puts "sleeping ##{i}" | |
sleep 1 | |
end | |
puts "" | |
puts "----------------------------------" | |
puts "|But with the power of celluloid!|" | |
puts "----------------------------------" | |
puts "" | |
(1..10).pmap do |i| | |
puts "sleeping ##{i}" | |
sleep 1 | |
end | |
puts "done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment