Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6797229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:35:01+00:00 2026-05-26T18:35:01+00:00

I’m using Ruby’s EventMachine library for accessing external RESTful APIs asynchronously from a Ruby

  • 0

I’m using Ruby’s EventMachine library for accessing external RESTful APIs asynchronously from a Ruby server I’m writing. One of the methods I make available through my server requires that multiple external APIs be accessed and the responses aggregated before returning a response to the client accessing my server. Here’s how I’m doing it now…

def aggregate
  responses = Array.new
  done      = 0

  # clients are EM::Deferrable objects...
  clients.each do |client|
    client.callback do |response|
      responses << response
      done += 1
    end

    client.errback do |response|
      done += 1
    end
  end

  until done == clients.length
    sleep 1
  end

  return responses
end

Are there better ways of handling this type of situation? Is it possible that the EM::Completion class being shipped in version 1.0.0 of EventMachine will provide plumbing that better supports such a use case?

I’m sure this issue has come up before (although I couldn’t find a similar question on StackOverflow), so I’m curious to see how others have approached the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:35:02+00:00Added an answer on May 26, 2026 at 6:35 pm

    First of all, using sleep entirely defeats the purpose of EventMachine. You’re blocking the event loop with it. I’d need a bigger picture for a suggestion on how to do it better, but your code should get used to the fact that a method returns before all requests are done. Alternatively look at em-synchrony for how to do procedural style evented programming with Ruby’s fibers (transparent to you).

    One way to reduce the glue code to run multiple requests in parallel is to use something like em-http-requests multi interface, which works with both EventMachine’s callback way, and em-synchrony too.

    EM::Completion on the other hand is more of an extended Deferrable, won’t exactly help you in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.