Reputation: 1608
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.
Upvotes: 2
Views: 344
Reputation: 5993
sleep
is an overridden keyword in Celluloid
, so if you want sleep
from Ruby
itself, use Kernel.sleep
. But that being said, as of 0.17.0-dependent
branch of Celluoid::IO
this error you describe does not exist ( anymore? ).
I used your reproducible failing case to test the new celluloid-pool
gem being released in version 0.17.0
of Celluloid
, and it is working no problem with sleep 1
as is.
Upvotes: 1