mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-05-01 13:32:14 +00:00
feat: add early token recycling in
This commit is contained in:
parent
e1e3be8106
commit
a5b54a7017
@ -45,6 +45,7 @@ class DialRequest {
|
||||
const th = new FIFO()
|
||||
tokens.forEach(t => th.push(t))
|
||||
const dialAbortControllers = this.addrs.map(() => new AbortController())
|
||||
let completedDials = 0
|
||||
|
||||
try {
|
||||
return await pAny(this.addrs.map(async (addr, i) => {
|
||||
@ -56,9 +57,17 @@ class DialRequest {
|
||||
// Remove the successful AbortController so it is no aborted
|
||||
dialAbortControllers.splice(i, 1)
|
||||
} catch (err) {
|
||||
th.push(token) // return to token holder on error so another ma can be attempted
|
||||
throw err
|
||||
} finally {
|
||||
completedDials++
|
||||
// If we have more dials to make, recycle the token, otherwise release it
|
||||
if (completedDials < this.addrs.length) {
|
||||
th.push(token)
|
||||
} else {
|
||||
this.dialer.releaseToken(tokens.splice(tokens.indexOf(token), 1)[0])
|
||||
}
|
||||
}
|
||||
|
||||
return conn
|
||||
}))
|
||||
} finally {
|
||||
|
Loading…
x
Reference in New Issue
Block a user