How to use the redux-saga/effects.cancelled function in redux-saga

To help you get started, we’ve selected a few redux-saga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enjeyw / Data-App-Boilerplate / client / sagas / authSagas.js View on Github external
function* requestToken(auth0_accessToken) {
  try {
    const token_request = yield call(requestApiToken, auth0_accessToken);
    yield put({type: LOGIN_SUCCESS, token: token_request.token});
    yield call(storeToken, token_request.token );
    return token_request
  } catch(error) {
    yield put({type: LOGIN_FAILURE, error: error.statusText})
  } finally {
    if (yield cancelled()) {
      // ... put special cancellation handling code here
    }
  }
}
github Festify / app / src / sagas / playback-state.ts View on Github external
const updateTask: Task = yield takeEveryWithState(
            [UPDATE_PARTY, UPDATE_PLAYBACK_STATE],
            playbackSelector,
            handlePartyUpdate,
        );

        // Wait for cancellation of this saga (occurs when party is left)
        yield join(
            becomeTask,
            resignTask,
            stateTask,
            updateTask,
        );
    } finally {
        // Remove playback state from DB when party is left while we're playing
        if (yield cancelled() && isPlaybackMaster) {
            firebase.database()
                .ref('/parties')
                .child(partyId)
                .child('playback')
                .update({
                    master_id: null,
                    playing: false,
                });
        }
    }
}
github elastic / kibana / x-pack / legacy / plugins / code / public / sagas / project_status.ts View on Github external
return function*(repoUri: RepositoryUri) {
    try {
      while (true) {
        // Delay at the beginning to allow some time for the server to consume the
        // queue task.
        yield call(delay, REPO_STATUS_POLLING_FREQ_MS);

        const repoStatus = yield call(fetchStatus, repoUri);
        const keepPolling = yield handleStatus(repoStatus, repoUri);
        if (!keepPolling) {
          yield put(pollingStopActionFunction(repoUri));
        }
      }
    } finally {
      if (yield cancelled()) {
        // Do nothing here now.
      }
    }
  };
}
github themgoncalves / react-adventure / source / app / state / sagas / auth.js View on Github external
function* login(email, password) { // eslint-disable-line no-unused-vars
  try {
    yield put({ type: AUTH_USER.SUCCESS });
    yield put(push('/'));
  } catch (err) {
    yield put({ type: AUTH_USER.FAILURE, err });
  } finally {
    if (yield cancelled()) {
      yield put(push('/login'));
    }
  }
}
github textileio / photos / App / features / contacts / sagas.ts View on Github external
try {
    while (true) {
      const event: SearchEvent = yield take(channel)
      switch (event.type) {
        case 'contact':
          yield put(actions.searchResultTextile(event.contact))
          break
        case 'error':
          yield put(actions.searchErrorTextile(event.error))
          break
      }
    }
  } catch (error) {
    yield put(actions.searchErrorTextile(error))
  } finally {
    if (yield cancelled()) {
      channel.close()
    } else {
      yield put(actions.textileSearchComplete())
      channel.close() // Think we want to do this to remove the event subscription
    }
  }
}
github ipfs-shipyard / paperhub / app / scripts / utils / saga-helpers.js View on Github external
export function * handleEvent (chan, handler) {
  try {
    while (true) {
      yield take(chan)
      yield call(handler)
    }
  } finally {
    if (yield cancelled()) {
      chan.close()
    }
  }
}
github AdactiveSAS / adsum-react-components / packages / adsum-screensaver / src / ScreenSaverSagas.js View on Github external
function* startModalTimer(counter: number) {
    try {
        while (counter !== 0) {
            yield delay(1000);
            yield put(decrementModal());
            counter--;
        }
        yield put(closeModal('openContent'));
    } finally {
        if (yield cancelled()) yield put(closeModal());
    }
}
github microsoft / BotFramework-WebChat / packages / core / src / sagas / postActivitySaga.js View on Github external
const {
      send: { echoBack }
    } = yield race({
      send: all({
        echoBack: echoBackCall,
        postActivity: observeOnce(directLine.postActivity(activity))
      }),
      timeout: call(() => sleep(sendTimeout).then(() => Promise.reject(new Error('timeout'))))
    });

    yield put({ type: POST_ACTIVITY_FULFILLED, meta, payload: { activity: echoBack } });
  } catch (err) {
    yield put({ type: POST_ACTIVITY_REJECTED, error: true, meta, payload: err });
  } finally {
    if (yield cancelled()) {
      yield put({ type: POST_ACTIVITY_REJECTED, error: true, meta, payload: new Error('cancelled') });
    }
  }
}