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

205
Vistas
How can I call a function for each array item BUT NOT have them all run at the same time

I was surprised I couldn't find an example of this anywhere, Im sure there is one but I seem to be having a hard time finding one.

I have an array of links... const array = ["www.google.com", "www.yahoo.com", "www.disney.com"];

and a function that takes a link and goes to the page and does some stuff and then closes with a resolve. I want to run the function using each array item but I don't want the functions to run all at once.

I tried array.forEach((item) => { functionThatUsesArrayData(item) }) but this runs each scraper all at once.

In one function id like to be able to use an array of links and pass each link the the function but launch them one at a time...so when the first link is done being scraped, the next array item will be used in a function and be scraped.

function(arrayItem).then(()=> function(arrayItem2)).then(()=> function(arrayItem3); Somthing like this...I feel like I should be able to do this with promises but I just cant seem to figure it out.

This is a small example...the real code I have is a web scraper that has an array of links to scrape but I dont want to have 10 pages of puppeteer up scraping at once, I need it to happen one after the other. Any ideas? Thank you!

async function functionThatUsesArrayData(link) {

    const chromeOptions = {
        headless: false,
        slowMo: 60,
        defaultViewport: null,
        args: ["--no-sandbox", "--disable-setuid-sandbox"],
    };
    const promise = new Promise(async (resolve, reject) => {
        const browser = await puppeteer.launch(chromeOptions);
        const page = await browser.newPage();
        await page.goto(link);
        await browser.close();
        resolve(setTimeout(() => {
            console.log(" TASKS FINSIHED COMPLETED")

        }, 3000))
    })
    console.log(promise)

}

functionThatUsesArrayData()```

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