Last active
January 4, 2016 13:09
-
-
Save cheald/8626291 to your computer and use it in GitHub Desktop.
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' | |
$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