Function: watchSignal()
API / @xmachines/play-signals / watchSignal
function watchSignal<T>(signal, onValue): () => void;Defined in: packages/play-signals/src/watch-signal.ts:21
Subscribe to a single signal using the canonical one-shot watcher lifecycle.
The callback runs from a queued microtask after pending notifications are drained, then the watcher re-arms itself so future updates are not missed. The returned cleanup keeps teardown idempotent by tolerating already-detached watchers.
Memory safety (Phase 29):
disposedflag prevents post-cleanup callback execution: if cleanup is called before a pending microtask fires, the microtask returns early.needsEnqueueguard dedups rapid synchronous signal changes: only one microtask is ever queued per batch of synchronous mutations.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
signal | | State<T> | Computed<T> | A Signal.State or Signal.Computed to subscribe to. |
onValue | (value) => void | Called with the current signal value after each change. |
Returns
A cleanup function that unregisters the watcher.
() => void