): ForkEffect
/**
* Spawns a `saga` on an action dispatched to the Store that matches `pattern`.
* Saga will be called after it stops taking `pattern` actions for `ms`
* milliseconds. Purpose of this is to prevent calling saga until the actions
* are settled off.
*
* #### Example
*
* In the following example, we create a basic task `fetchAutocomplete`. We use
* `debounce` to delay calling `fetchAutocomplete` saga until we stop receive
* any `FETCH_AUTOCOMPLETE` events for at least `1000` ms.
*
* import { call, put, debounce } from `redux-saga/effects`
*
* function* fetchAutocomplete(action) {
* const autocompleteProposals = yield call(Api.fetchAutocomplete, action.text)
* yield put({type: 'FETCHED_AUTOCOMPLETE_PROPOSALS', proposals: autocompleteProposals})
* }
*
* function* debounceAutocomplete() {
* yield debounce(1000, 'FETCH_AUTOCOMPLETE', fetchAutocomplete)
* }
*
* #### Notes
*
* `debounce` is a high-level API built using `take`, `delay` and `fork`. Here
* is how the helper could be implemented using the low-level Effects
*
* const debounce = (ms, pattern, task, ...args) => fork(function*() {
* while (true) {
* let action = yield take(pattern)
*
* while (true) {
* const { debounced, _action } = yield race({
* debounced: delay(ms),
* _action: take(pattern)
* })
*
* if (debounced) {
* yield fork(worker, ...args, action)
* break
* }
*
* action = _action
* }
* }
* })
*
* @param ms defines how many milliseconds should elapse since the last time
* `pattern` action was fired to call the `saga`
* @param pattern for more information see docs for `take(pattern)`
* @param saga a Generator function
* @param args arguments to be passed to the started task. `debounce` will add
* the incoming action to the argument list (i.e. the action will be the last
* argument provided to `saga`)
*/
export function debounce(
ms: number,
pattern: P,
worker: (action: ActionMatchingPattern
) => any,
): ForkEffect
export function debounce any>(
ms: number,
pattern: P,
worker: Fn,
...args: HelperWorkerParameters, Fn>
): ForkEffect
export function debounce(
ms: number,
pattern: ActionPattern,
worker: (action: A) => any,
): ForkEffect
export function debounce any>(
ms: number,
pattern: ActionPattern,
worker: Fn,
...args: HelperWorkerParameters
): ForkEffect
/**
* You can also pass in a channel as argument and the behaviour is the same as
* `debounce(ms, pattern, saga, ...args)`.
*/
export function debounce(ms: number, channel: TakeableChannel, worker: (item: T) => any): ForkEffect
export function debounce any>(
ms: number,
channel: TakeableChannel,
worker: Fn,
...args: HelperWorkerParameters
): ForkEffect
/**
* Creates an Effect description that instructs the middleware to call the
* function `fn` with `args` as arguments. In case of failure will try to make
* another call after `delay` milliseconds, if a number of attempts < `maxTries`.
*
* #### Example
*
* In the following example, we create a basic task `retrySaga`. We use `retry`
* to try to fetch our API 3 times with 10 second interval. If `request` fails
* first time than `retry` will call `request` one more time while calls count
* less than 3.
*
* import { put, retry } from 'redux-saga/effects'
* import { request } from 'some-api';
*
* function* retrySaga(data) {
* try {
* const SECOND = 1000
* const response = yield retry(3, 10 * SECOND, request, data)
* yield put({ type: 'REQUEST_SUCCESS', payload: response })
* } catch(error) {
* yield put({ type: 'REQUEST_FAIL', payload: { error } })
* }
* }
*
* @param maxTries maximum calls count.
* @param delay length of a time window in milliseconds between `fn` calls.
* @param fn A Generator function, or normal function which either returns a
* Promise as a result, or any other value.
* @param args An array of values to be passed as arguments to `fn`
*/
export function retry any>(
maxTries: number,
delayLength: number,
fn: Fn,
...args: Parameters
): CallEffect>
/**
* Creates an Effect description that instructs the middleware to run multiple
* Effects in parallel and wait for all of them to complete. It's quite the
* corresponding API to standard
* [`Promise#all`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all).
*
* #### Example
*
* The following example runs two blocking calls in parallel:
*
* import { fetchCustomers, fetchProducts } from './path/to/api'
* import { all, call } from `redux-saga/effects`
*
* function* mySaga() {
* const [customers, products] = yield all([
* call(fetchCustomers),
* call(fetchProducts)
* ])
* }
*/
export function all(effects: T[]): AllEffect
/**
* The same as `all([...effects])` but let's you to pass in a dictionary object
* of effects with labels, just like `race(effects)`
*
* @param effects a dictionary Object of the form {label: effect, ...}
*/
export function all(effects: { [key: string]: T }): AllEffect
export type AllEffect = CombinatorEffect<'ALL', T>
export type AllEffectDescriptor = CombinatorEffectDescriptor
/**
* Creates an Effect description that instructs the middleware to run a *Race*
* between multiple Effects (this is similar to how
* [`Promise.race([...])`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
* behaves).
*
*
* #### Example
*
* The following example runs a race between two effects:
*
* 1. A call to a function `fetchUsers` which returns a Promise
* 2. A `CANCEL_FETCH` action which may be eventually dispatched on the Store
*
*
* import { take, call, race } from `redux-saga/effects`
* import fetchUsers from './path/to/fetchUsers'
*
* function* fetchUsersSaga() {
* const { response, cancel } = yield race({
* response: call(fetchUsers),
* cancel: take(CANCEL_FETCH)
* })
* }
*
* If `call(fetchUsers)` resolves (or rejects) first, the result of `race` will
* be an object with a single keyed object `{response: result}` where `result`
* is the resolved result of `fetchUsers`.
*
* If an action of type `CANCEL_FETCH` is dispatched on the Store before
* `fetchUsers` completes, the result will be a single keyed object
* `{cancel: action}`, where action is the dispatched action.
*
* #### Notes
*
* When resolving a `race`, the middleware automatically cancels all the losing
* Effects.
*
* @param effects a dictionary Object of the form {label: effect, ...}
*/
export function race(effects: { [key: string]: T }): RaceEffect
/**
* The same as `race(effects)` but lets you pass in an array of effects.
*/
export function race(effects: T[]): RaceEffect
export type RaceEffect = CombinatorEffect<'RACE', T>
export type RaceEffectDescriptor