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

216
Visualizações
Is there a way to get values of only resolved promises?

I'm calling multiple services which includes network calls and other asynchronous services in my JavaScript application.

At first I was invoking these promises one by one. In the long run it's getting hard to maintain since I'm invoking more services.

I read somewhere in the internet that we can use Promise.all() to group all promises and execute everything at a time.

The issue is, if any one of the promise is getting rejected all other promises are also getting rejected, this is not what I need.

I'm working in a status dashboard where I need to ping multiple services and show whether the service is up or not. By using Promise.all, it's not working in a way I wished.

Tried another method Promise.any(), but it just resolves when any one is resolved.

Took a look at MDN docs, there are many functions for promise it's overwhelming to me because I'm a beginner in JavaScript.

Currently I've created a very own service which takes care of calling all the promises and counts with the response. Is there any cleaner way to do it?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use Promise.allSettled, then filter out those that weren't fulfilled.

Promise.allSettled([
  Promise.resolve(3),
  Promise.reject(4),
  Promise.resolve(5),
])
  .then((results) => {
    const allFulfilledValues = results
      .filter(r => r.status === 'fulfilled')
      .map(r => r.value);
    console.log(allFulfilledValues);
  });

about 4 years ago · Juan Pablo Isaza 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