Skip to content

Commit

Permalink
klicker: Prevent concurrent calls to tokenProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
schneefux committed Dec 24, 2024
1 parent 8bada13 commit e9114d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions klicker/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class HttpTransport implements ITransport<ResultSet> {
export class KlickerService implements IKlickerService {
private cubejsApi: CubeApi
private transport: HttpTransport
private tokenPromise: Promise<void>|undefined
public visualisations: VisualisationSpec[] = defaultVisualisations
public staticWidgets: StaticWidgetSpec[] = defaultStaticWidgets
public slicers: SlicerSpec[] = []
Expand Down Expand Up @@ -124,12 +125,25 @@ export class KlickerService implements IKlickerService {
}

private async updateCubeToken() {
const token = await this.tokenProvider()
if (token == undefined) {
throw new Error('No authentication token available')
// prevent concurrent calls to tokenProvider
if (this.tokenPromise) {
return this.tokenPromise
}

this.transport.authorization = token
this.tokenPromise = (async () => {
try {
const token = await this.tokenProvider()
if (token == undefined) {
throw new Error('No authentication token available')
}

this.transport.authorization = token
} finally {
this.tokenPromise = undefined
}
})();

return this.tokenPromise
}

// override & extend
Expand Down
2 changes: 1 addition & 1 deletion web/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,6 @@
"metric.accountCreationYear": "Account Created",
"metric.highestRank": "Highest Rank",
"metric.masteryPoints": "Mastery Points",
"mode.wipeout5v5": "Wipeout 5v5",
"mode.wipeout5V5": "Wipeout 5v5",
"mode.paintBrawl": "Paint Brawl"
}

0 comments on commit e9114d0

Please sign in to comment.