Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top