@@ -86,14 +86,39 @@ are used in applications that still rely on ZoneJS.
8686
8787If you are using SSR with Angular, you may know that it relies on ZoneJS to help determine when the application
8888is "stable" and can be serialized. If there are asynchronous tasks that should prevent serialization, an application
89- not using ZoneJS will need to make Angular aware of these with the ` PendingTasks ` service. Serialization
89+ not using ZoneJS must make Angular aware of these with the [ PendingTasks] ( /api/core/PendingTasks ) service. Serialization
9090will wait for the first moment that all pending tasks have been removed.
9191
92+
93+ The two most straightforward uses of pending tasks are the ` run ` method:
94+
95+ ``` typescript
96+ const taskService = inject (PendingTasks );
97+ taskService .run (async () => {
98+ const someResult = await doSomeWorkThatNeedsToBeRendered ();
99+ this .someState .set (someResult );
100+ });
101+ ```
102+
103+ For more complicated use-cases, you can manuall add and remove a pending tasks:
104+
92105``` typescript
93106const taskService = inject (PendingTasks );
94107const taskCleanup = taskService .add ();
95- await doSomeWorkThatNeedsToBeRendered ();
96- taskCleanup ();
108+ try {
109+ await doSomeWorkThatNeedsToBeRendered ();
110+ } catch {
111+ // handle error
112+ } finally {
113+ taskCleanup ();
114+ }
115+ ```
116+
117+ In addition, the [ pendingUntilEvent] ( /api/core/rxjs-interop/pendingUntilEvent# ) helper in ` rxjs-interop ` ensures
118+ the application remains unstable until the observable emits, complets, errors, or is unsubscribed.
119+
120+ ``` typescript
121+ readonly myObservableState = someObservable .pipe (pendingUntilEvent ());
97122```
98123
99124The framework uses this service internally as well to prevent serialization until asynchronous tasks are complete. These include, but are not limited to,
0 commit comments