Skip to content

Commit 7220a3c

Browse files
committed
using promiseFactory as base instead of Promise[]
1 parent f5d6117 commit 7220a3c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

packages/sessions/src/trackers/multiple.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ export class MultipleTracker implements migrator.PresignedMigrationTracker, Conf
5858
) {}
5959

6060
async configOfImageHash(args: { imageHash: string }): Promise<commons.config.Config | undefined> {
61-
const requests = this.trackers.map(async (t, i) => ({ res: await t.configOfImageHash(args), i }))
61+
const requestFactory = this.trackers.map((t, i) => async () => ({ res: await t.configOfImageHash(args), i }))
6262

6363
let result1: { res: commons.config.Config | undefined; i: number } | undefined
6464

6565
if (this.isSerial) {
66-
result1 = await serialResolve(
67-
requests.map(p => () => p),
66+
result1 = await serialResolve(requestFactory, undefined, val => {
67+
if (val?.res === undefined) return false
68+
return universal.genericCoderFor(val.res.version).config.isComplete(val.res)
69+
})
70+
} else {
71+
// We try to find a complete configuration, we race so that we don't wait for all trackers to respond
72+
result1 = await raceUntil(
73+
requestFactory.map(p => p()),
6874
undefined,
6975
val => {
7076
if (val?.res === undefined) return false
7177
return universal.genericCoderFor(val.res.version).config.isComplete(val.res)
7278
}
7379
)
74-
} else {
75-
// We try to find a complete configuration, we race so that we don't wait for all trackers to respond
76-
result1 = await raceUntil(requests, undefined, val => {
77-
if (val?.res === undefined) return false
78-
return universal.genericCoderFor(val.res.version).config.isComplete(val.res)
79-
})
8080
}
8181

8282
if (result1?.res) {
@@ -90,7 +90,10 @@ export class MultipleTracker implements migrator.PresignedMigrationTracker, Conf
9090
// but we try to combine all results anyway
9191
const tmptracker = new LocalConfigTracker(undefined as any) // TODO: Fix this, provider not needed anyway
9292

93-
const results = await allSafe(requests, undefined)
93+
const results = await allSafe(
94+
requestFactory.map(p => p()),
95+
undefined
96+
)
9497

9598
for (const r of results) {
9699
if (r?.res) await tmptracker.saveWalletConfig({ config: r.res })
@@ -114,16 +117,16 @@ export class MultipleTracker implements migrator.PresignedMigrationTracker, Conf
114117
wallet: string
115118
}): Promise<{ imageHash: string; context: commons.context.WalletContext } | undefined> {
116119
let imageHash: { imageHash: string; context: commons.context.WalletContext } | undefined
117-
const requests = this.trackers.map(t => t.imageHashOfCounterfactualWallet(args))
120+
const requestFactory = this.trackers.map(t => () => t.imageHashOfCounterfactualWallet(args))
118121

119122
if (this.isSerial) {
120-
imageHash = await serialResolve(
121-
requests.map(p => () => p),
123+
imageHash = await serialResolve(requestFactory, undefined, result => Boolean(result))
124+
} else {
125+
imageHash = await raceUntil(
126+
requestFactory.map(p => p()),
122127
undefined,
123128
result => Boolean(result)
124129
)
125-
} else {
126-
imageHash = await raceUntil(requests, undefined, result => Boolean(result))
127130
}
128131

129132
if (imageHash) {

0 commit comments

Comments
 (0)