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

202
Views
Para la función de titiritero de ejecución de bucle fuera de servicio

Tengo un bucle que contiene una función de titiritero. El problema es que el bucle está haciendo todo el titiritero al mismo tiempo.

He intentado esto:

 import puppeteer from "puppeteer" (async function(){ for(let i = 0; i < 3; i++){ await launchPup().then(() => { }); } })() async function launchPup() { puppeteer.launch({headless: false}).then(async browser => { await browser.newPage() await browser.close() }) }

¿Podría decirme qué estoy haciendo mal y cómo puedo solucionarlo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Es una función asíncrona, debe observar el navegador creado.

algo como esto debería ayudarte.

 var totalOpenedbrowser = 0; var minBrowser = 2; const wait = () => new Promise((resolve) => setTimeout(resolve, 200)) (async function() { for (let i = 0; i < 3; i++) { await launchPup().then(() => {}); } })() async function launchPup() { while (totalOpenedbrowser > = minBrowser) await wait(); // wait until there is a free slott totalOpenedbrowser++; puppeteer.launch({ headless: false }).then(async browser => { await browser.newPage() await browser.close() totalOpenedbrowser--; }) }

Eche un vistazo a la biblioteca que construyo, resolverá su problema https://www.npmjs.com/package/puppeteer-express

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!