MCPcopy Index your code
hub / github.com/angular/angular / SubscribableStrategy

Class SubscribableStrategy

packages/common/src/pipes/async_pipe.ts:34–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34class SubscribableStrategy implements SubscriptionStrategy {
35 createSubscription(
36 async: Subscribable<any>,
37 updateLatestValue: any,
38 onError: (e: unknown) => void,
39 ): Unsubscribable {
40 // Subscription can be side-effectful, and we don't want any signal reads which happen in the
41 // side effect of the subscription to be tracked by a component's template when that
42 // subscription is triggered via the async pipe. So we wrap the subscription in `untracked` to
43 // decouple from the current reactive context.
44 //
45 // `untracked` also prevents signal _writes_ which happen in the subscription side effect from
46 // being treated as signal writes during the template evaluation (which throws errors).
47 return untracked(() =>
48 async.subscribe({
49 next: updateLatestValue,
50 error: onError,
51 }),
52 );
53 }
54
55 dispose(subscription: Unsubscribable): void {
56 // See the comment in `createSubscription` above on the use of `untracked`.
57 untracked(() => subscription.unsubscribe());
58 }
59}
60
61class PromiseStrategy implements SubscriptionStrategy {
62 createSubscription(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…