Skip to content

Instantly share code, notes, and snippets.

@DanielVartanov
Last active August 29, 2015 14:10
Show Gist options
  • Save DanielVartanov/0f0753b1aca9060fcd3c to your computer and use it in GitHub Desktop.
Save DanielVartanov/0f0753b1aca9060fcd3c to your computer and use it in GitHub Desktop.
require 'celluloid'
class Cell
include Celluloid
def initialize
@condition = Celluloid::Condition.new
end
def wait(number)
async.wait_for(number)
end
def signal
@condition.signal
end
protected
def wait_for(number)
puts "Waiting #{number}"
@condition.wait
puts "Waiting complete #{number}"
end
end
instance = Cell.new
5.times.map { |n| instance.wait(n) }
instance.signal
sleep
=begin
Output:
"""
Waiting 0
Waiting 1
Waiting 2
Waiting 3
Waiting 4
Waiting complete 0
"""
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment