Skip to content

Instantly share code, notes, and snippets.

@anibal
Created July 12, 2010 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anibal/472969 to your computer and use it in GitHub Desktop.
Save anibal/472969 to your computer and use it in GitHub Desktop.
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