I recommend using the Observer pattern. Celluloid supports this via Notifications. Take a look at the wiki for some information: https://github.com/celluloid/celluloid/wiki/Notifications
Here's a working code example:
require 'rubygems'
require 'celluloid/autostart'
class Test
include Celluloid
include Celluloid::Notifications
def initialize(aaa)
@aaa = aaa
end
def foo
sleep 2
@bbb = 'asdasd'
publish "done!", "Slept for 2 seconds and set @bbb = #{@bbb}"
end
def bar
"aaa is: #{@aaa}, bbb is: #{@bbb}"
end
end
class Observer
include Celluloid
include Celluloid::Notifications
def initialize
subscribe "done!", :on_completion
end
def on_completion(*args)
puts "finished, returned #{args.inspect}"
end
end
y = Observer.new
x = Test.new 111
x.async.foo
sleep 3