Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

431
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda