Skip to content

Instantly share code, notes, and snippets.

@jasonroelofs
Last active December 27, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonroelofs/7405029 to your computer and use it in GitHub Desktop.
Save jasonroelofs/7405029 to your computer and use it in GitHub Desktop.
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
Copy link

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