Created
July 12, 2010 19:48
-
-
Save anibal/472969 to your computer and use it in GitHub Desktop.
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
def http_get(url) | |
f = Fiber.current | |
http = EventMachine::HttpRequest.new(url).get | |
# resume fiber once http call is done | |
http.callback { f.resume(http) } | |
http.errback { f.resume(http) } | |
return Fiber.yield | |
end | |
EventMachine.run do | |
Fiber.new{ | |
page = http_get('http://www.google.com/') | |
puts "Fetched page: #{page.response_header.status}" | |
if page | |
page = http_get('http://www.google.com/search?q=eventmachine') | |
puts "Fetched page 2: #{page.response_header.status}" | |
end | |
}.resume | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment