Hi,
I want to make two asynchronous calls on a Ruby on Rails server. One HTTP request and one database query. After both calls are finished then I will merge them to become one single JSON object.
After spending many hours on the internet, the closest thing I could find is em-synchrony. Just like EventMachine and Fiber, no oracle database support is mentioned anywhere.
Is it doable?
If that's not the right approach, how could it be done? Should I create a new Thread for one of the request then join them?
require 'eventmachine'
require 'em-synchrony'
require 'em-synchrony/em-http'
EM.synchrony do
multi = EventMachine::Synchrony::Multi.new
multi.add :page2, { return "5" }
data = multi.perform.responses[:callback].values
EM::Synchrony::Iterator.new(data, 2).each do |page, iter|
end
puts "All done! Stopping event loop."
EventMachine.stop
end