queue
The createQueue() function creates a FIFO queue that limits how many tasks run in parallel and exposes their results through promises.
Interactive example
Syntax
typescript
interface Queue {
add<GenericOutput extends unknown>(
theFunction: () => GenericOutput
): Promise<
| Awaited<GenericOutput>
| DEither.Left<"execution-error", unknown>
>;
addExternal(): Promise<() => void>;
}
interface CreateQueueParams {
concurrency?: number;
}
function createQueue(
params?: CreateQueueParams
): Queue;Parameters
params.concurrency: Maximum number of tasks executed in parallel. Values lower than1fall back to1.
Return value
A Queue object with:
add: adds a task to the queue and returns a promise resolved with its result or withDEither.left("execution-error", error)when execution fails.addExternal: reserves one execution slot and returns areleasefunction to free that slot later.
See also
externalPromise- Creates a promise controllable from the outsidecallThen- Normalizes sync and async value handlingasyncRetry- Retries an async operation with a retry strategy
