reconnecter: clear timeout on connect.

This commit is contained in:
Miroslav Šedivý 2021-07-17 15:30:56 +02:00
parent 0974beaf4a
commit b3a8d5f86d

View File

@ -127,6 +127,11 @@ export class Reconnecter extends EventEmitter<ReconnecterEvents> {
} }
public close(error?: Error): void { public close(error?: Error): void {
if (this._timeout) {
window.clearTimeout(this._timeout)
this._timeout = undefined
}
if (!this._open) { if (!this._open) {
throw new Error('connection is already closed') throw new Error('connection is already closed')
} }
@ -141,6 +146,11 @@ export class Reconnecter extends EventEmitter<ReconnecterEvents> {
} }
public connect(): void { public connect(): void {
if (this._timeout) {
window.clearTimeout(this._timeout)
this._timeout = undefined
}
this._conn.connect() this._conn.connect()
this._timeout = window.setTimeout(this.onDisconnect.bind(this), this._config.timeoutMs) this._timeout = window.setTimeout(this.onDisconnect.bind(this), this._config.timeoutMs)
} }