asyncSignal

G
W

"Flattens" a source of promises or observables to a signal of result values, switching to the new source as soon as it changes.

To avoid confusion an observable of observables is not "flattened." This is so observables passed in as the valueSource can create a writable signal. The function toSignal can be used if this behavior is necessary.

This function is most convenient when you need to execute an asynchronous request when a signal changes. As seen in the example below, you can mix signals and observables by wrapping them in an anonymous function. This function is converted to a computed signal that returns an observable. Every time a signal changes, asyncSignal will unsubscribe from the old observable and subscribe to the new one, behaving similarly to an Rxjs switchMap.

Execute Async Requests When a Signal Changes