Skip to content

Instantly share code, notes, and snippets.

@yoojinl
Created October 29, 2011 20:19
Show Gist options
  • Save yoojinl/1325034 to your computer and use it in GitHub Desktop.
Save yoojinl/1325034 to your computer and use it in GitHub Desktop.
Actors shmactors.
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