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.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/em/dns_cache.rb', line 212 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
244 245 246 247 248 |
# File 'lib/em/dns_cache.rb', line 244 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 |