[]previous and next page

flush

Runs every pending effect now: what the scheduled microtask does.

Runs every pending effect now: what the scheduled microtask does. Drains the queues until nothing is pending; render effects always run before user effects, parents before children, siblings by creation, and effects woken by a write in the flush run in a following pass. Errors nobody handled are collected and thrown once the queues are empty, so one failing effect never wedges the rest. Does nothing when a flush is already running. Transition-lane effects are not run here: they wait for the lane. Prefer flushSync in application code.

Import#

ts
import { flush } from "@shadow-js/core/extend";

Signature#

ts
function flush(): void

Throws#

  • The error of an effect that no error handler caught; several are thrown together as an AggregateError.
  • ShadowError INFINITE_LOOP when effects keep waking each other for more than 1000 passes: the queued effects are dropped and the flush stops.

Examples#

ts
import { flush, writeSignal, type SignalNode } from "@shadow-js/core/extend";

export function setNow(signal: SignalNode<number>, value: number): void {
  writeSignal(signal, value);
  flush(); // the effects that read the signal have run
}