refactor: remove timer utilities from Client (#6113)

This commit is contained in:
Antonio Román
2021-07-16 14:31:25 +02:00
committed by GitHub
parent f200f14a40
commit 5ca97c9351
13 changed files with 47 additions and 145 deletions

View File

@@ -84,8 +84,8 @@ class Collector extends EventEmitter {
this.handleCollect = this.handleCollect.bind(this);
this.handleDispose = this.handleDispose.bind(this);
if (options.time) this._timeout = this.client.setTimeout(() => this.stop('time'), options.time);
if (options.idle) this._idletimeout = this.client.setTimeout(() => this.stop('idle'), options.idle);
if (options.time) this._timeout = setTimeout(() => this.stop('time'), options.time).unref();
if (options.idle) this._idletimeout = setTimeout(() => this.stop('idle'), options.idle).unref();
}
/**
@@ -108,8 +108,8 @@ class Collector extends EventEmitter {
this.emit('collect', ...args);
if (this._idletimeout) {
this.client.clearTimeout(this._idletimeout);
this._idletimeout = this.client.setTimeout(() => this.stop('idle'), this.options.idle);
clearTimeout(this._idletimeout);
this._idletimeout = setTimeout(() => this.stop('idle'), this.options.idle).unref();
}
}
this.checkEnd();
@@ -179,11 +179,11 @@ class Collector extends EventEmitter {
if (this.ended) return;
if (this._timeout) {
this.client.clearTimeout(this._timeout);
clearTimeout(this._timeout);
this._timeout = null;
}
if (this._idletimeout) {
this.client.clearTimeout(this._idletimeout);
clearTimeout(this._idletimeout);
this._idletimeout = null;
}
this.ended = true;
@@ -211,12 +211,12 @@ class Collector extends EventEmitter {
*/
resetTimer({ time, idle } = {}) {
if (this._timeout) {
this.client.clearTimeout(this._timeout);
this._timeout = this.client.setTimeout(() => this.stop('time'), time ?? this.options.time);
clearTimeout(this._timeout);
this._timeout = setTimeout(() => this.stop('time'), time ?? this.options.time).unref();
}
if (this._idletimeout) {
this.client.clearTimeout(this._idletimeout);
this._idletimeout = this.client.setTimeout(() => this.stop('idle'), idle ?? this.options.idle);
clearTimeout(this._idletimeout);
this._idletimeout = setTimeout(() => this.stop('idle'), idle ?? this.options.idle).unref();
}
}