Last active
August 29, 2015 14:10
-
-
Save DanielVartanov/0f0753b1aca9060fcd3c 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 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