-
-
Save halorgium/83098ca88ad6dda4a65e to your computer and use it in GitHub Desktop.
This file contains 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
source "https://rubygems.org" | |
gem "celluloid", github: "celluloid/celluloid" | |
gem "celluloid-io", github: "celluloid/celluloid-io" | |
gem "atomic" |
This file contains 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/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