Reputation: 175
I tried get data from rest api using http requests and evenmachine. For this use em-net-http, fibers(ruby1.9.2p290). My pseudocode look like this:
EM.run do
Fiber.new do
api_client.get_data_1
end.resume
Fiber.new do
api_client.get_data_2
end.resume
...
Fiber.new do
api_client.get_data_n
end.resume
EventMachine.stop
end
Question: How stop EM after all data loaded? I counted requests but this bad practice. Is there any pattern to do this? I also used em-synchrony but this slower for me.
Thanks
Upvotes: 0
Views: 109
Reputation: 4473
Use em-http-request and the multi-http interface which provides a call back for when all the requests have been completed. The example provided in the second link does pretty much what you're after.
Upvotes: 1