Skip to content

Instantly share code, notes, and snippets.

@FranDepascuali
Created September 7, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FranDepascuali/84a7fce339d64b26a5ff93d84e66f438 to your computer and use it in GitHub Desktop.
Save FranDepascuali/84a7fce339d64b26a5ff93d84e66f438 to your computer and use it in GitHub Desktop.
bar vs foo
function* watchTokenExpire() {
let action = yield take(UPDATE_TOKEN_EXPIRE);
while (true) {
if (action.payload.shouldRefresh) {
yield fetchNewTokenOrLogout();
} else {
const expireInMs = (action.payload.expireIn * 1000) - MIN_TOKEN_LIFESPAN;
const raceResult = yield race({
action: take(UPDATE_TOKEN_EXPIRE),
timeout: delay(expireInMs),
});
if (raceResult.timeout) {
yield fetchNewTokenOrLogout();
} else {
({ action } = raceResult);
}
}
}
}
function* watchTokenExpire() {
const expireInMs = Number.MAX_SAFE_INTEGER;
while (true) {
const raceResult = yield race({
action: take(UPDATE_TOKEN_EXPIRE),
timeout: delay(expireInMs),
});
if (raceResult.action.payload.expireIn) {
expireInMs = (raceResult.action.payload.expireIn * 1000) - MIN_TOKEN_LIFESPAN;
}
if (raceResult.action.payload.shouldRefresh || raceResult.timeout) {
yield fetchNewTokenOrLogout()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment