apopovych
apopovych

Reputation: 175

Stop evenmachine after all data loaded with many fibers

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

Answers (1)

George
George

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

Related Questions