You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Cancels the listener instance that made this call.
365
365
*/
366
366
cancel: () =>void
367
+
/**
368
+
* Throws a `TaskAbortError` if this listener has been cancelled
369
+
*/
370
+
throwIfCancelled: () =>void
367
371
/**
368
372
* An abort signal whose `aborted` property is set to `true`
369
373
* if the listener execution is either aborted or completed.
@@ -408,6 +412,7 @@ These can be divided into several categories.
408
412
-`subscribe: () => void`: will re-subscribe the listener entry if it was previously removed, or no-op if currently subscribed
409
413
-`cancelActiveListeners: () => void`: cancels all other running instances of this same listener _except_ for the one that made this call. (The cancellation will only have a meaningful effect if the other instances are paused using one of the cancellation-aware APIs like `take/cancel/pause/delay` - see "Cancelation and Task Management" in the "Usage" section for more details)
410
414
-`cancel: () => void`: cancels the instance of this listener that made this call.
415
+
-`throwIfCancelled: () => void`: throws a `TaskAbortError` if the current listener instance was cancelled.
411
416
-`signal: AbortSignal`: An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) whose `aborted` property will be set to `true` if the listener execution is aborted or completed.
412
417
413
418
Dynamically unsubscribing and re-subscribing this listener allows for more complex async workflows, such as avoiding duplicate running instances by calling `listenerApi.unsubscribe()` at the start of a listener, or calling `listenerApi.cancelActiveListeners()` to ensure that only the most recent instance is allowed to complete.
@@ -645,6 +650,8 @@ The listener middleware supports cancellation of running listener instances, `ta
645
650
646
651
The `listenerApi.pause/delay()` functions provide a cancellation-aware way to have the current listener sleep. `pause()` accepts a promise, while `delay` accepts a timeout value. If the listener is cancelled while waiting, a `TaskAbortError` will be thrown. In addition, both `take` and `condition` support cancellation interruption as well.
647
652
653
+
`listenerApi.cancelActiveListeners()` will cancel _other_ existing instances that are running, while `listenerApi.cancel()` can be used to cancel the _current_ instance (which may be useful from a fork, which could be deeply nested and not able to directly throw a promise to break out of the effect execution). `listenerAPi.throwIfCancelled()` can also be useful to bail out of workflows in case cancellation happened while the effect was doing other work.
654
+
648
655
`listenerApi.fork()` can used to launch "child tasks" that can do additional work. These can be waited on to collect their results. An example of this might look like:
0 commit comments