Last active
December 27, 2015 23:19
-
-
Save jasonroelofs/7405029 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.