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

121
Visualizações
How to check/debug state of individual promises in a promise.all

I'm shoving a bunch of script nodes with no src attribute into an array of promises that sets the src and then resolves or rejects, respectively onload or onerror. All of these are called in a Promise.all which I await. The problem is, it never stops waiting. I presume some of the individual promises are resolving or rejecting, but I can't figure out how to debug which ones aren't.

  function loadScript (script) {
    return new Promise(function(resolve, reject) {
      // this happens for every script
      script.setAttribute("src", script.getAttribute("data-src"));
      script.onload = _ => resolve(script.src);
      script.onerror = _ => reject(script.src);
    });
  }
  
  // loadScripts : (graph, int) -> (string array) promise
  async function loadScripts(g, order = 1) {
    if (!g.has(order))
      return []
    else
      return [
        ...await Promise.all(g.get(order).map(loadScript)),
        // the script stops here after the first pass and never executes the
        // next line. It just ... awaits the previous line
        ...await loadScripts(g, order + 1)
      ]
  }

I got to this point by setting breakpoints in Chrome devtools and stepping, but I'm not sure, once we're sitting and awaiting, how to check the state of the individual promises, to see which ones are resolving and which are still pending.

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