I suggest adding pools and workers for them, possibly a separate library.
This can be useful, for example, when you need to complete tasks in different ways; for this, separate workers are needed. Or, for example, there are tasks to get information from the API, but there is a limit, we can add another worker with a separate API key.
I already made a fork and tried to implement workers, it works. but it seems to me it is better to rewrite everything as a separate library.
Some ideas:
const pool = new Pool({
// ?workers: []
// ?resolveWorker: 'loop'|'random'|'priority'
});
const worker1 = new Worker({
concurrency: 20,
intervalCap: 100,
interval: 1000,
timeout: 1000,
throwOnTimeout: true,
// ??priority,
// ctx: {apiUrl: "https://.."} ??
// process: async payload => { ??
// return await (await fetch('https://specialEndPointForWorker/'+payload.id)).json();
// }
});
const worker2 = new Worker({
concurrency: 50,
intervalCap: 200,
interval: 1000,
});
pool.attachWorker(worker1);
pool.attachWorker(worker2); // or pool.detachWorker(worker2); runtime control
pool.add(async ({ worker }) => {
// console.log(`Fetchind... ${worker.ctx.apiUrl}`); ??
await setTimeout(1000);
console.log(`Task done! Worker#${[worker1, worker2].indexOf(worker) + 1}`);
return "payload string";
});
worker1.pause(); // or pool.detachWorker(worker1);
pool.pause();
pool.on("completed", ({ payload, worker }) => {});
worker1.on("completed", payload => {});
// ...
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too