Skip to content

Instantly share code, notes, and snippets.

@hinrik
Created March 19, 2012 13:26
Show Gist options
  • Save hinrik/2112033 to your computer and use it in GitHub Desktop.
Save hinrik/2112033 to your computer and use it in GitHub Desktop.
require 'celluloid'
class PluginOne
include Celluloid
def foo(args)
args[:first_added] = true
yield :continue
end
end
class PluginTwo
include Celluloid
def foo(args)
args[:second_added] = true
yield :stop # third plugin will never see the event
end
end
class PluginThird
include Celluloid
def foo(args)
yield :continue
end
end
class Manager
include Celluloid
def initialize
@plugins = [PluginOne.new, PluginTwo.new, PluginThird.new]
end
def process(events)
events.each do |event, args|
actor = Celluloid.current_actor
@plugins.each do |plugin|
plugin.send "#{event}!", args do |status|
actor.mailbox << PluginStatus.new(status)
end
args = args.dup # avoid action at a distance
message = receive { |m| m.is_a? PluginStatus }
p args
puts message.type
break if message.type == :stop
end
end
end
end
class PluginStatus
attr_accessor :type
def initialize(type)
@type = type
end
end
manager = Manager.new
manager.process({ foo: {} })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment