asyncFoldExhaust<S, A> static method

FlowHandle asyncFoldExhaust<S, A>(
  1. Cell source, {
  2. required A seed,
  3. required FutureOr<A> accumulate(
    1. A acc,
    2. S value
    ),
  4. FoldSnapshot<A>? snapshot,
  5. FoldErrorHandler? onError,
})

Similar to asyncFold, but ignores new triggers while an inner accumulation is already running.

When to use

Use asyncFoldExhaust when you want to prevent overlapping state updates.

  • Submit Buttons: Preventing multiple form submissions from corrupting the accumulated state.
  • Resource Locking: Ensuring a state update finishes before accepting the next.

How it works

  1. The first incoming pulse starts the accumulate function.
  2. While the accumulation is running, new triggers are dropped.
  3. When the accumulation completes, the next trigger is accepted.

Implementation

static FlowHandle asyncFoldExhaust<S, A>(
  Cell source, {
  required A seed,
  required FutureOr<A> Function(A acc, S value) accumulate,
  FoldSnapshot<A>? snapshot,
  FoldErrorHandler? onError,
}) {
  return AsyncFoldExhaust<S, A>(
    seed,
    accumulate,
    snapshot: snapshot,
    onError: onError,
  ).toHandle(source: source);
}