Skip to content

Instantly share code, notes, and snippets.

@jasonroelofs

jasonroelofs/test_actor.rb

Last active Dec 27, 2015
Embed
What would you like to do?
require 'celluloid'
class TestActor
include Celluloid
def initialize
@handlers = []
end
def add_handler(&block)
@handlers << block
end
def fire
@handlers.each { |block| block.call }
end
end
obj = TestActor.new
obj.add_handler do
puts "Handler 1 fired"
end
obj.add_handler do
puts "Handler 2 fired"
end
obj.fire
# Deadlock death
@halorgium

This comment has been minimized.

Copy link

@halorgium halorgium commented Nov 11, 2013

You need to use execute_block_on_receiver :add_handler to tell Celluloid to execute the block in the actor context.

See the wiki.
We also have a bug surrounding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.