Skip to content

Instantly share code, notes, and snippets.

@cheald
Last active January 4, 2016 13:09
Show Gist options
  • Save cheald/8626291 to your computer and use it in GitHub Desktop.
Save cheald/8626291 to your computer and use it in GitHub Desktop.
require 'celluloid'
$count = 0
$start = Time.now.to_f
class FooActor
include Celluloid
def listen
while true do
x = Celluloid::Actor[:bar_actor_pool]
x.async.do_stuff if x
end
end
end
class BarActor
include Celluloid
def do_stuff
$count += 1
rate = $count.to_f / (Time.now.to_f - $start)
puts "%s <Thread %s> - %2.1f/s" % [self.object_id, Thread.current.object_id, rate]
end
end
class FooSupervisor < Celluloid::SupervisionGroup
pool BarActor, as: "bar_actor_pool", size: 5
pool FooActor, as: "foo_actor_pool", size: 5
end
puts "Running..."
FooSupervisor.run!
5.times { Celluloid::Actor[:foo_actor_pool].async.listen }
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment