Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

429
Views
How to get results from Concurrent::Promise::all?

Using conccurrent-ruby, how can I execute a set of promises and then get the results?

Here is an example of what I would like to be able to do (The test passes because it never reaches the 'then' block.

it "can aggregate the results" do
  Concurrent::Promise::all?(
    Concurrent::Promise.execute { 42 },
    Concurrent::Promise.execute { 43 },
  ).then do |result|
      binding.pry
      expect(result).to eq([42, 43])
    end
end
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In order to execute the the .all? promises you need to call .execute and .wait, that means it will execute then wait until the result is ready, note wait is blocking meaning it will block your code`. ex:


Concurrent::Promise.all?(
  Concurrent::Promise.new { 42 },
  Concurrent::Promise.new { 43 }
).then do |result|
  puts 'finished promises'
end.execute.wait

However if you wish to get the results after the promises are finished you can use .zip method, ex:


Concurrent::Promise.zip(
  Concurrent::Promise.execute { 42 },
  Concurrent::Promise.execute { 43 }
).then do |result|
  expect(result).to eq([42, 43])
end.wait

Note: There are some differences between .zip and .all? check the docs: https://www.rubydoc.info/gems/concurrent-ruby/Concurrent/Promise

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!