Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
}
}
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,
});
}
}
}
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.
}
}
};
}
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'));
}
}
}
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
}
}
}
function cancelledTest() {
const c = cancelled();
(c.CANCELLED: Object);
}
export function * handleEvent (chan, handler) {
try {
while (true) {
yield take(chan)
yield call(handler)
}
} finally {
if (yield cancelled()) {
chan.close()
}
}
}
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());
}
}
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') });
}
}
}