em-synchrony.rb implements this feature with Fibers but I would go for a non-Fibre version with 1.8 MRI.
EM.run do
http = EM::Protocols::HttpClient2.connect("www.google.com", 80)
request = http.get("/")
request.callback do
puts request.status
EM.stop
end
end
Have a look at em-http-request:
EM.run do
http1 = EventMachine::HttpRequest.new('http://example.com/1').get
http1.callback do
p http1.response
end
http2 = EventMachine::HttpRequest.new('http://example.com/2').get
http2.callback do
p http2.response
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With