Skip to content

Commit 266f1ed

Browse files
committed
Added cancel() to createListenerMiddleware.mdx
I somehow didn't include this with my previous commit, oops.
1 parent 92b475a commit 266f1ed

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

docs/api/createListenerMiddleware.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ export interface ListenerEffectAPI<
360360
* Cancels all other running instances of this same listener except for the one that made this call.
361361
*/
362362
cancelActiveListeners: () => void
363+
/**
364+
* Cancels the listener instance that made this call.
365+
*/
366+
cancel: () => void
363367
/**
364368
* An abort signal whose `aborted` property is set to `true`
365369
* if the listener execution is either aborted or completed.
@@ -403,6 +407,7 @@ These can be divided into several categories.
403407
- `unsubscribe: () => void`: removes the listener entry from the middleware, and prevent future instances of the listener from running. (This does _not_ cancel any active instances.)
404408
- `subscribe: () => void`: will re-subscribe the listener entry if it was previously removed, or no-op if currently subscribed
405409
- `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+
- `cancel: () => void`: cancels the instance of this listener that made this call.
406411
- `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.
407412

408413
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.
@@ -666,7 +671,7 @@ listenerMiddleware.startListening({
666671
667672
### Complex Async Workflows
668673
669-
The provided async workflow primitives (`cancelActiveListeners`, `unsubscribe`, `subscribe`, `take`, `condition`, `pause`, `delay`) can be used to implement behavior that is equivalent to many of the more complex async workflow capabilities found in the Redux-Saga library. This includes effects such as `throttle`, `debounce`, `takeLatest`, `takeLeading`, and `fork/join`. Some examples from the test suite:
674+
The provided async workflow primitives (`cancelActiveListeners`, `cancel`, `unsubscribe`, `subscribe`, `take`, `condition`, `pause`, `delay`) can be used to implement behavior that is equivalent to many of the more complex async workflow capabilities found in the Redux-Saga library. This includes effects such as `throttle`, `debounce`, `takeLatest`, `takeLeading`, and `fork/join`. Some examples from the test suite:
670675
671676
```js
672677
test('debounce / takeLatest', async () => {

0 commit comments

Comments
 (0)