Skip to content

Instantly share code, notes, and snippets.

@phil
Created June 11, 2014 13:10
Show Gist options
  • Save phil/78bcfb5034eadc30d30e to your computer and use it in GitHub Desktop.
Save phil/78bcfb5034eadc30d30e to your computer and use it in GitHub Desktop.
EventMachine HTTP Response
require "eventmachine"
require "em-http-request"
EventMachine.run do
sites = ["http://kyan.com"] * 20
sites.each_with_index do |site,i|
http = EM::HttpRequest.new(site).get
http.callback do
# remove the site from the array
sites.pop
# Output some data about the site
puts "#{site} - #{i} - #{http.response_header.status}"
# Check to see if this was the last site and exit
EM.stop if sites.empty?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment