I'm using Celluloid::IO to do DNS query and below is my code:
require 'celluloid/io'
class MyResolver
include Celluloid::IO
def initialize
@resolver = DNSResolver.new
end
def resolve(domain)
ips = @resolver.resolve domain
#sleep 1
return {domain: domain, ip: ips}
end
end
pool = MyResolver.pool(size: 5)
domains = [
'www.google.com',
## many other record
]
futures = domains.map {|d| pool.future.resolve(d)}
futures.each do |future|
puts "#{future.value}"
end
This code works and finished in few seconds. But when I add the line sleep 1(just for learning purpose), after printing some results, the process blocked forever, which is very strange.
Thanks for any help.
sleepis an overridden keyword inCelluloid, so if you wantsleepfromRubyitself, useKernel.sleep. But that being said, as of0.17.0-dependentbranch ofCelluoid::IOthis error you describe does not exist ( anymore? ).I used your reproducible failing case to test the new
celluloid-poolgem being released in version0.17.0ofCelluloid, and it is working no problem withsleep 1as is.