Created
June 11, 2014 13:10
-
-
Save phil/78bcfb5034eadc30d30e to your computer and use it in GitHub Desktop.
EventMachine HTTP Response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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