Ruby on Rails
Saturday, September 19, 2015
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 :page1, EventMachine::HttpRequest.new("http://google.com/search?q=eventmachine").aget
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
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bd617700-e7bf-49da-954f-437f2cb68ece%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment