Skip to content

Commit

Permalink
Use set for parachain url cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn committed Sep 16, 2024
1 parent be6b4cf commit 5ca0a25
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions centrifuge-js/src/CentrifugeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ type Events = ISubmittableResult['events']

const txCompletedEvents: Record<string, Subject<Events>> = {}
const blockEvents: Record<string, Observable<Events>> = {}
let parachainUrlCache: string | null = null
const parachainUrlCache = new Set<string | null>()

export class CentrifugeBase {
config: Config
Expand Down Expand Up @@ -347,15 +347,15 @@ export class CentrifugeBase {
}

private async getCachedParachainUrl(): Promise<string> {
const cachedUrl = parachainUrlCache
if (cachedUrl) {
return cachedUrl
if (parachainUrlCache.values().next().value) {
return parachainUrlCache.values().next().value
}
parachainUrlCache = await this.findHealthyWs()
if (!parachainUrlCache) {
const healthyUrl = await this.findHealthyWs()
if (!healthyUrl) {
throw new Error('No healthy parachain URL available')
}
return parachainUrlCache
parachainUrlCache.add(healthyUrl)
return healthyUrl
}

async getChainId() {
Expand Down

0 comments on commit 5ca0a25

Please sign in to comment.