Skip to content

Instantly share code, notes, and snippets.

@aflatter
Forked from eswdd/future_sample.rb
Last active December 24, 2015 11:29
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 aflatter/6791057 to your computer and use it in GitHub Desktop.
Save aflatter/6791057 to your computer and use it in GitHub Desktop.
require 'celluloid'
def pusher(condition)
sleep 5
condition.signal 'Wibble'
end
def puller(condition)
value = condition.wait
puts "Pulled: #{value}"
end
condition = Celluloid::Condition.new
t1 = Thread.new {
begin
puller(condition)
rescue Exception => e
puts "Exception raised: #{e.message}\n #{e.backtrace.join("\n ")}"
end
}
t2 = Thread.new {
begin
pusher(condition)
rescue Exception => e
puts "Exception raised: #{e.message}\n #{e.backtrace.join("\n ")}"
end
}
t1.join
t2.join
__END__
$ ruby test.rb
Pulled: Wibble
D, [2013-10-02T11:12:19.773810 #12311] DEBUG -- : Shutdown completed cleanly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment