0

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

apopovych
  • 175
  • 1
  • 7
  • I suspect your code is doing requests sequentially. No idea how em-synchrony can be slower than a sequential download. Please provide a benchmark with results. – phil pirozhkov Aug 12 '12 at 02:21

1 Answers1

1

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.

George
  • 4,273
  • 2
  • 15
  • 10