Created
October 29, 2011 20:19
-
-
Save yoojinl/1325034 to your computer and use it in GitHub Desktop.
Actors shmactors.
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 'thread' | |
require 'celluloid' | |
$q = Queue.new | |
class A | |
include Celluloid | |
def add | |
loop do | |
sleep 3 | |
value = rand 100 | |
$q.push value | |
puts "A add: #{value}" | |
end | |
end | |
end | |
class B | |
include Celluloid | |
def add | |
loop do | |
sleep 3 | |
value = rand 100 | |
$q.push value | |
puts "B add: #{value}" | |
end | |
end | |
end | |
class C | |
include Celluloid | |
def get | |
loop do | |
sleep 3 | |
puts "C get: #{$q.pop}" unless $q.empty? | |
end | |
end | |
end | |
a = A.new | |
b = B.new | |
c = C.new | |
a.add! | |
b.add! | |
c.get! | |
a.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment