Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Refresh access_token if expired #24

Merged
merged 9 commits into from Nov 5, 2020

avoid exponential growth of token pool

  • Loading branch information
fcjr committed Nov 5, 2020
commit 86b9395693f05954346d6d3bbf0d105779de06b7
@@ -1,4 +1,5 @@
const PUBLIC_EXP = 65537;
const MIN_TOKENS = 6;

function bnToBase64(bn) {
return sjcl.codec.base64.fromBits(bn.toBits());
@@ -16,7 +17,7 @@ class TokenPool {
async getToken() {
if (this.tokens.length === 0) {
await this.generateTokens();
} else if (this.tokens.length < 6) {
} else if (this.tokens.length < MIN_TOKENS) {
this.generateTokens();
}
return this.tokens.pop();
@@ -39,6 +40,11 @@ class TokenPool {
}

async generateTokens() {
// avoid exponential growth of the token pool
if (this.tokens.length >= MIN_TOKENS) {
return;
}

const accessToken = AccessToken.get();
if (!accessToken) {
return;
ProTip! Use n and p to navigate between commits in a pull request.