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

198
Visualizações
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 à 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