How many tasks can run simultaneously
Milliseconds to wait after one task starts before the next starts
A function that accepts a task (a function returning a Promise) and returns a Promise of its result.
Example usage:
const limit = createDelayedPLimit(2, 100); // concurrency=2, delay=100ms
async function doAsync(label: string) {
console.log(`Starting: ${label}`);
await new Promise((r) => setTimeout(r, 500));
console.log(`Finished: ${label}`);
return label;
}
// Queue some tasks
const tasks = ['A', 'B', 'C', 'D'].map(
(label) => limit(() => doAsync(label)),
);
// Wait for all
const results = await Promise.all(tasks);
console.log(results); // ['A', 'B', 'C', 'D']
Creates a concurrency-limited queue with a fixed delay between the start times of tasks.