Created
September 7, 2018 16:33
-
-
Save FranDepascuali/84a7fce339d64b26a5ff93d84e66f438 to your computer and use it in GitHub Desktop.
bar vs foo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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