debounce
The debounce() function delays a flow execution. If a new run of the same flow arrives before the delay ends, the previous run is cancelled and returns params.returnValue.
Interactive example
Syntax
typescript
function debounce<
GenericValue extends unknown = undefined
>(
time: number,
params?: {
returnValue?: GenericValue;
}
): AsyncGeneratorParameters
time: Delay to wait before allowing the current execution to continue.params.returnValue: Value returned when a previous run is replaced during the debounce delay.
Return value
debounce() returns an async generator. The runner waits for the delay before continuing the last preserved run, and completes replaced runs with params.returnValue.
Notes
- Internal state is stored in a
WeakMapkeyed by the executed flow reference. - To share the same debounce window 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 thedebounce()state. - If the same execution yields
debounce(...)multiple times, only the first encountered effect is applied by the runner.
See also
throttling- Ignores or defers runs that happen too close together without waiting for the latest runqueue- Serializes runs instead of cancelling the previous onerun- Executes the flow and applies debounce effects
