Skip to content

Commit a5b54a7

Browse files
committed
feat: add early token recycling in
1 parent e1e3be8 commit a5b54a7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/dialer/dial-request.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class DialRequest {
4545
const th = new FIFO()
4646
tokens.forEach(t => th.push(t))
4747
const dialAbortControllers = this.addrs.map(() => new AbortController())
48+
let completedDials = 0
4849

4950
try {
5051
return await pAny(this.addrs.map(async (addr, i) => {
@@ -56,9 +57,17 @@ class DialRequest {
5657
// Remove the successful AbortController so it is no aborted
5758
dialAbortControllers.splice(i, 1)
5859
} catch (err) {
59-
th.push(token) // return to token holder on error so another ma can be attempted
6060
throw err
61+
} finally {
62+
completedDials++
63+
// If we have more dials to make, recycle the token, otherwise release it
64+
if (completedDials < this.addrs.length) {
65+
th.push(token)
66+
} else {
67+
this.dialer.releaseToken(tokens.splice(tokens.indexOf(token), 1)[0])
68+
}
6169
}
70+
6271
return conn
6372
}))
6473
} finally {

0 commit comments

Comments
 (0)