Class: EventMachine::Udns::Multi
- Inherits:
-
Object
- Object
- EventMachine::Udns::Multi
- Includes:
- Deferrable
- Defined in:
- lib/em-udns-multi.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(timeout = nil) ⇒ Multi
constructor
A new instance of Multi.
- #query(name, target, type = 'A') ⇒ Object
Constructor Details
#initialize(timeout = nil) ⇒ Multi
Returns a new instance of Multi.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/em-udns-multi.rb', line 9 def initialize(timeout = nil) @responses, @pending = {}, [] EventMachine.next_tick do # Initialize the resolver. EventMachine::Udns.run(resolver) # Since udns's timeout is private, use our own. on_timeout = proc { cancel_pending_queries! } EventMachine::Timer.new(timeout, &on_timeout) if timeout end end |
Instance Method Details
#finished? ⇒ Boolean
35 36 37 |
# File 'lib/em-udns-multi.rb', line 35 def finished? resolver.active == 0 end |
#query(name, target, type = 'A') ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/em-udns-multi.rb', line 22 def query(name, target, type = 'A') raise "EM::Udns doesn't know about #{type} records!" unless known_record_type?(type) # When a result comes in, add it to the list or results. on_any_response = proc { |result| update_progress!(name, result) } # Add this query to the list of pending ones, so the timer can cancel them if necessary. @pending << @resolver.send("submit_#{type}", target).tap do |this| this.callback(&on_any_response) this.errback(&on_any_response) end end |