while-fetch-execute
While you can fetch, execute
Fetch jobs, and while you have any jobs, execute them, N in parallel. Only fetches a job when a worker is idle.
Micro-example:
async function jobFetch() {
if (!doneForSomeReason) {
return null;
}
return nextJob();
}
async function jobExecute(job) {
//...
await doYourOwnMagic(job);
//...
}
async function main() {
await whileFetchExecute(8, jobFetch, jobExecute);
}
main();