mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-24 18:12:14 +00:00
fix: retimer reschedule does not work as interval (#710)
* fix: retimer reschedule does not work as interval * chore: apply suggestions from code review Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com>
This commit is contained in:
parent
99ff361a55
commit
999c1b7740
@ -178,7 +178,7 @@ class ConnectionManager extends EventEmitter {
|
||||
const total = received + sent
|
||||
this._checkMaxLimit('maxData', total)
|
||||
log('metrics update', total)
|
||||
this._timer.reschedule(this._options.pollInterval)
|
||||
this._timer = retimer(this._checkMetrics, this._options.pollInterval)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,17 +291,9 @@ class ConnectionManager extends EventEmitter {
|
||||
async _autoDial () {
|
||||
const minConnections = this._options.minConnections
|
||||
|
||||
const recursiveTimeoutTrigger = () => {
|
||||
if (this._autoDialTimeout) {
|
||||
this._autoDialTimeout.reschedule(this._options.autoDialInterval)
|
||||
} else {
|
||||
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
||||
}
|
||||
}
|
||||
|
||||
// Already has enough connections
|
||||
if (this.size >= minConnections) {
|
||||
recursiveTimeoutTrigger()
|
||||
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
||||
return
|
||||
}
|
||||
|
||||
@ -332,7 +324,7 @@ class ConnectionManager extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
recursiveTimeoutTrigger()
|
||||
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,11 +128,7 @@ class Stats extends EventEmitter {
|
||||
* @returns {void}
|
||||
*/
|
||||
_resetComputeTimeout () {
|
||||
if (this._timeout) {
|
||||
this._timeout.reschedule(this._nextTimeout())
|
||||
} else {
|
||||
this._timeout = retimer(this._update, this._nextTimeout())
|
||||
}
|
||||
this._timeout = retimer(this._update, this._nextTimeout())
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user