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:
Vasco Santos 2020-07-14 19:11:29 +02:00 committed by GitHub
parent 99ff361a55
commit 999c1b7740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 16 deletions

View File

@ -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)
}
/**

View File

@ -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())
}
/**