Takes an async source (Promise, Observable) or signal/function that returns an async source and returns that source's values as part of a signal. Kind of like an rxjs flattening operator. When the async source changes, the old source is immediately released and the new source is listened.

A Promise or Subscribable to create writable signal, otherwise a signal or function that returns a Promise or Subscribable.

The options for the async signal

a signal that returns values from the async source..

$id = signal(0);
// call getCustomer every time $id changes.
$customer = asyncSignal(() => this.$id() !== 0 ? this.getCustomer(this.$id()) : undefined);

constructor() {
// writable overload can switch versions.
const artificialWritableExampleSource1 = new BehaviorSubject(1);
const $writable = asyncSignal(artificialWritableExampleSource1);
const artificialWritableExampleSource2 = new BehaviorSubject(2);
$writable.set(artificialWritableExampleSource2);
}