queue
The queue() function reserves a slot for the current execution so you can serialize or limit concurrent runs of the same flow.
Interactive example
Syntax
typescript
function queue<
GenericConcurrency extends number
>(
params?: {
concurrency?: GenericConcurrency;
}
): AsyncGeneratorParameters
params.concurrency: Maximum number of simultaneous runs allowed for the same flow reference. The default is1.
Return value
An async generator yielding a queue effect and returning a release function that must be called when the execution can free its slot, usually from a finally block.
Notes
- Internal state is stored in a
WeakMapkeyed by the executed flow reference. - To share the same queue across calls, reuse the same flow created with
F.create(...)or the same function returned byF.toFunction(...). - If
release()is never called, later runs remain blocked in the queue. - If the same execution yields
queue(...)multiple times, only the first encountered effect is applied by the runner.
See also
calledByNext- Calls a callback when a later run replaces the current onethrottling- Ignores or defers runs that happen too close togetherexec- Executes a nested flow inside the current flow
