Skip to content

Instantly share code, notes, and snippets.

@bensie
Created June 7, 2012 17:45
Show Gist options
  • Select an option

  • Save bensie/2890315 to your computer and use it in GitHub Desktop.

Select an option

Save bensie/2890315 to your computer and use it in GitHub Desktop.
playing with celluloid
require "celluloid"
class Runner
include Celluloid
def initialize
if block_given?
puts "starting instance run"
yield self
puts "finished instance run"
end
end
def run
(1..10).map do |i|
run_pool.future(:do_stuff, i)
end.map(&:value)
end
def do_stuff(i)
puts "running on #{i}"
puts "finishing on #{i}"
end
private
def run_pool
@run_pool ||= Runner.pool(size: 2)
end
end
puts "Let's get started"
Runner.new do |r|
r.run
end
puts "Done with everything, move on"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment