Skip to content

Instantly share code, notes, and snippets.

@halorgium
Last active December 27, 2015 18:39
Show Gist options
  • Save halorgium/83098ca88ad6dda4a65e to your computer and use it in GitHub Desktop.
Save halorgium/83098ca88ad6dda4a65e to your computer and use it in GitHub Desktop.
source "https://rubygems.org"
gem "celluloid", github: "celluloid/celluloid"
gem "celluloid-io", github: "celluloid/celluloid-io"
gem "atomic"
require "celluloid/test"
require "celluloid/io"
require "atomic"
Celluloid.boot
class A
include Celluloid::IO
class B
include Celluloid
def foo; end
end
def listen
# B.new_link # this works!
socket = TCPSocket.new("www.google.com", 80)
$reference.update { |x| x + 1 }
# B.new.foo # for some reason, this solves the problem too
B.new_link # this does not work!
$counter.update { |x| x + 1 }
end
end
$counter = Atomic.new(0)
$reference = Atomic.new(0)
20.times { A.new.async.listen }
puts "Wait 5 seconds."
10.times.each do |i|
puts "second #{i}"
puts "Total: #{$counter.value} of #{$reference.value}"
#Celluloid.dump
sleep(1)
end
Celluloid.dump
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment