@laserware/stasis
    Preparing search index...

    Function race

    • Creates an Effect description that instructs the middleware to run a Race between multiple Effects (this is similar to how Promise.race([...]) behaves).

      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.

      When resolving a race, the middleware automatically cancels all the losing Effects.

      Type Parameters

      • T

      Parameters

      • effects: { [key: string]: T }

        a dictionary Object of the form {label: effect, ...}

      Returns RaceEffect<T>

    • The same as race(effects) but lets you pass in an array of effects.

      Type Parameters

      • T

      Parameters

      • effects: T[]

      Returns RaceEffect<T>