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

217
Visualizações
Determine when jszip async function is complete

How can I let spellcheckePub() function know when gatherWords() function is fully done executing? gatherWords() is processing epub books so it takes a while and when I console.log(words) it is empty, presumably because the forEach hasn't completed yet.

masterePub is a zip(epub) loaded with jszip. forEach executes for each file/dir listing in loaded zip file.

 function spellcheckePub() {
      gatherWords();
      console.log(words);
      // do stuff with words
 }

    function gatherWords() {
      words = [];
      masterePub.forEach(function (relativePath, file) {
        if (!file.dir) {
          masterePub.file(file.name).async("text")
          .then(function success(content) {
            //make an array of words
            content = content.split(/\s+/);
            words = words.concat(content);
          });
        }
      });
    } // end spellcheckePub function
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Collect the promises you create in an array, call Promise.all on it:

async function spellcheckePub() {
  const words = await gatherWords();
  console.log(words);
  // do stuff with words
}

async function gatherWords() {
  const promises = [];
  masterePub.forEach((relativePath, file) => {
    if (!file.dir) {
      promises.push(file.async("text").then(content => {
        //make an array of words
        return content.split(/\s+/);
      }));
    }
  });
  const wordArrays = await Promise.all(promises);
  return wordArrays.flat();
}
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