Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

441
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda