I'm running the lighthouse cli against a ~50 site list of sites. I'm simply running it in a .forEach
loop, which, if I understand, is blocking, aka, synchronous. However, I end up spinning up 50 Chrome Canary instances all at once. In my limited understanding of these things I think the thread is started synchronously, but then node
can pass the thread off to the kernel and happily start the next. Again, that's just my hand-wavy understanding of what's going on.
I'm using this function that I cribbed from somewhere:
function launchChromeAndLighthouse(url, opts, config = null) {
return chromeLauncher.launch({chromeFlags: opts.chromeFlags}).then(chrome => {
opts.port = chrome.port;
return lighthouse(url, opts, config).then(results =>
chrome.kill().then(() => results));
});
}
I tried nextTick
in the loop:
asyncFuncs().then( async (sites) => {
sites.forEach( (site) => {
process.nextTick(launchChromeAndRunLighthouse(site.url, opts))
})
})
But this still spawns a bunch of Chrome instances. How do I pause execution while one lighthouse completes?