Cancels all other running instances of this same listener except for the one that made this call.
Returns a promise that resolves when the input predicate returns true or
rejects if the listener has been cancelled or is completed.
The return value is true if the predicate succeeds or false if a timeout is provided and expires first.
const updateBy = createAction<number>('counter/updateBy');
middleware.startListening({
actionCreator: updateBy,
async effect(_, { condition }) {
// wait at most 3s for `updateBy` actions.
if(await condition(updateBy.match, 3_000)) {
// `updateBy` has been dispatched twice in less than 3s.
}
}
})
An abort signal whose aborted property is set to true
if the listener execution is either aborted or completed.
Returns a promise that resolves when the input predicate returns true or
rejects if the listener has been cancelled or is completed.
The return value is the [action, currentState, previousState] combination that the predicate saw as arguments.
The promise resolves to null if a timeout is provided and expires first,
const updateBy = createAction<number>('counter/updateBy');
middleware.startListening({
actionCreator: updateBy,
async effect(_, { take }) {
const [{ payload }] = await take(updateBy.match);
console.log(payload); // logs 5;
}
})
store.dispatch(updateBy(5));
Throws a TaskAbortError if this listener has been cancelled
Returns a promise that resolves after timeoutMs or
rejects if the listener has been cancelled or is completed.
Queues in the next microtask the execution of a task.
Optionaloptions: ForkOptionsIt will subscribe a listener if it was previously removed, noop otherwise.
Removes the listener entry from the middleware and prevent future instances of the listener from running.
It does not cancel any active instances.
Cancels the instance of this listener that made this call.