Skip to content

Instantly share code, notes, and snippets.

@jeremyvdw
Created August 17, 2012 13:49
Show Gist options
  • Save jeremyvdw/3378835 to your computer and use it in GitHub Desktop.
Save jeremyvdw/3378835 to your computer and use it in GitHub Desktop.
Celluloid registry issue/weirdness
require 'celluloid'
require 'awesome_print'
Celluloid.logger = Logger.new STDOUT
class Monitor
include Celluloid
attr_reader :name
def initialize(name)
@name = name
end
end
class Manager
include Celluloid
def initialize
@names = [
'Paul',
'John',
'Ringo'
]
spawn_actors
every(5) { ap whos_there }
after(10) { killall_monitors }
end
def spawn_actors
@names.each do |name|
Supervisor.supervise_as(actors_name(name), Monitor, name)
end
end
def killall_monitors
@names.each do |name|
Celluloid::Actor[actors_name(name)].tap do |actor|
actor.terminate if actor.alive?
end
end
end
def whos_there
Celluloid::Actor.registered
end
private
def actors_name(name)
:"Monitor#{name}"
end
end
Celluloid::SupervisionGroup.new do |group|
group.supervise_as :Manager, Manager
end
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment