File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,21 @@ listenerMiddleware.startListening({
5454 // Use the listener API methods to dispatch, get state,
5555 // unsubscribe the listener, start child tasks, and more
5656 listenerApi .dispatch (todoAdded (' Buy pet food' ))
57- listenerApi .unsubscribe ()
57+
58+ // Spawn "child tasks" that can do more work and return results
59+ const task = listenerApi .fork (async (forkApi ) => {
60+ // Can pause execution
61+ await forkApi .delay (5 )
62+ // Complete the child by returning a value
63+ return 42
64+ })
65+
66+ const result = await task .result
67+ // Unwrap the child result in the listener
68+ if (result .status === ' ok' ) {
69+ // Logs the `42` result value that was returned
70+ console .log (' Child succeeded: ' , result .value )
71+ }
5872 }
5973 },
6074})
You can’t perform that action at this time.
0 commit comments