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

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

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 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