Sha256: 515d54f42936a7d7f1144b32c2093bf8def774e082b0605485348f61c806d4a6

Contents?: true

Size: 840 Bytes

Versions: 1

Compression:

Stored size: 840 Bytes

Contents

$: << File.dirname(__FILE__) + '/../lib'
require 'em-whois'
require 'atomic'

# Asynchronous, parallel multi-domain WHOIS lookup
domains = ARGV.empty? ? ["github.com", "google.com", "bing.com", "yahoo.com", "mikejarema.com"] : ARGV
whois   = {}

EM.synchrony do  
  
  # Progress indicator
  EM.add_periodic_timer(0.1) do
    STDERR.print "."
  end

  # Exit condition
  EM.add_periodic_timer(0.1) do
    if domains.size == whois.keys.size
      puts ""
      whois.each do |k,v|
        if v.properties[:available?]
          puts "#{k}: available"
        else
          puts "#{k}: taken, expires #{v.properties[:expires_on]}"
        end
      end

      EM.stop
    end
  end

  # Async WHOIS lookup - fire and forget via parallel fibers
  domains.each do |i|
    Fiber.new do
      whois[i] = Whois.whois(i)
    end.resume
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
em-whois-0.3.0 examples/async_parallel_whois.rb