calledByNext
The calledByNext() function registers a callback executed when a new run of the same flow replaces a previous asynchronous run that is still active. A common use case is aborting a previous fetch with AbortController.
Interactive example
Syntax
typescript
function calledByNext<
GenericOutput extends unknown
>(
theFunction: () => GenericOutput
): AsyncGeneratorParameters
theFunction: Callback called when a later run of the same flow arrives before the current run finishes.
Return value
An async generator yielding a calledByNext effect. The callback return value is not returned by the flow.
Notes
- Internal state is stored in a
WeakMapkeyed by the executed flow reference. - To share this behavior across calls, reuse the same flow created with
F.create(...)or the same function returned byF.toFunction(...). - An inline
F.run(async function *() { ... })creates a new reference on every call, so it does not share thecalledByNext()state. - If the same execution yields
calledByNext(...)multiple times, only the first encountered effect is applied by the runner.
See also
queue- Serializes or limits concurrent runs of the same flowthrottling- Ignores or defers runs that happen too close togetherexec- Executes a nested flow inside the current flow
