Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
Determinar cuándo se completa la función jszip asíncrona

¿Cómo puedo dejar que la función SpellcheckePub() sepa cuándo la función Recolectar Palabras() ha terminado de ejecutarse por completo? Reunir palabras () está procesando libros epub, por lo que lleva un tiempo y cuando consola. log (palabras) está vacío, presumiblemente porque forEach aún no se ha completado.

masterePub es un zip (epub) cargado con jszip . forEach se ejecuta para cada lista de archivos/directorios en el archivo zip cargado.

 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 answers
Answer question

0

Reúna las promesas que crea en una matriz, llame a Promise.all en él:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!