Class: EventMachine::DnsCache::MxQuery
- Inherits:
-
Object
- Object
- EventMachine::DnsCache::MxQuery
- Includes:
- EM::Deferrable
- Defined in:
- lib/em/dns_cache.rb
Instance Method Summary collapse
-
#initialize(rslt) ⇒ MxQuery
constructor
A new instance of MxQuery.
- #succeed_result ⇒ Object
Constructor Details
#initialize(rslt) ⇒ MxQuery
Returns a new instance of MxQuery.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/em/dns_cache.rb', line 265 def initialize rslt @result = rslt # Deferrable @n_a_lookups = 0 self.callback {|resp| addrs = {} resp.each_additional {|name,ttl,data| addrs.has_key?(name) ? (addrs[name] << data.address.to_s) : (addrs[name] = [data.address.to_s]) } @addresses = resp.answer. sort {|a,b| a[2].preference <=> b[2].preference}. map {|name,ttl,data| ex = data.exchange addrs[ex] or EM::DnsCache.resolve(ex.to_s) } @addresses.each_with_index {|a,ix| if a.respond_to?(:set_deferred_status) @n_a_lookups += 1 a.callback {|r| @addresses[ix] = r @n_a_lookups -= 1 succeed_result if @n_a_lookups == 0 } end } succeed_result if @n_a_lookups == 0 } end |
Instance Method Details
#succeed_result ⇒ Object
297 298 299 300 301 |
# File 'lib/em/dns_cache.rb', line 297 def succeed_result # Questionable whether we should uniq if it perturbs the sort order. # Also freeze it so some user can't wipe it out on us. @result.succeed @addresses.flatten.uniq.freeze end |