From 332ef318886ad7989c01218117309c9acc3f0981 Mon Sep 17 00:00:00 2001 From: olzzon Date: Tue, 26 Nov 2024 12:58:16 +0100 Subject: [PATCH 1/3] fix: emit error on timeout request and disconnect --- src/Ember/Client/index.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Ember/Client/index.ts b/src/Ember/Client/index.ts index 460475f..86c9084 100644 --- a/src/Ember/Client/index.ts +++ b/src/Ember/Client/index.ts @@ -130,11 +130,9 @@ export class EmberClient extends EventEmitter { this._client.on('error', (e) => this.emit('error', e)) this._client.on('connected', () => this.emit('connected')) this._client.on('disconnected', () => { - this._requests.forEach((req) => { - req.reject(new Error('Socket was disconnected')) - this._requests.delete(req.reqId) - }) - this.emit('disconnected') + // Clanup and Emit disconnected event, and let the client handle that the connection is lost + this._requests.clear() // Just clean up the requests + this.emit('disconnected') // Notify listeners about the disconnection }) } @@ -172,10 +170,10 @@ export class EmberClient extends EventEmitter { this._client.removeAllListeners() // @ts-expect-error: after using this method, properties are no longer expected to always exist delete this._client - this._requests.forEach((req) => { - req.reject(new Error('Socket was disconnected')) - this._requests.delete(req.reqId) - }) + this._client.on('disconnected', () => { + this._requests.clear(); // Just clean up the requests + this.emit('disconnected') // Notify listeners about the disconnection + }) clearInterval(this._timer) } @@ -722,11 +720,12 @@ export class EmberClient extends EventEmitter { if (sent) { req.lastSent = Date.now() } else { - req.reject(new Error('Request was not sent correctly')) + this.emit('error', new Error('Request was not sent correctly')) } } if (sinceFirstSent >= this._timeout) { - req.reject(new Error('Request timed out')) + // Emit error and remove request + this.emit('error', new Error('Request timed out')) this._requests.delete(req.reqId) } }) From 836db30792e1e7915651303a7ff716ef1206e0d0 Mon Sep 17 00:00:00 2001 From: olzzon Date: Wed, 27 Nov 2024 09:00:15 +0100 Subject: [PATCH 2/3] fix: prettier failing test --- src/Ember/Client/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Ember/Client/index.ts b/src/Ember/Client/index.ts index 86c9084..4e7eb71 100644 --- a/src/Ember/Client/index.ts +++ b/src/Ember/Client/index.ts @@ -171,9 +171,9 @@ export class EmberClient extends EventEmitter { // @ts-expect-error: after using this method, properties are no longer expected to always exist delete this._client this._client.on('disconnected', () => { - this._requests.clear(); // Just clean up the requests - this.emit('disconnected') // Notify listeners about the disconnection - }) + this._requests.clear() // Just clean up the requests + this.emit('disconnected') // Notify listeners about the disconnection + }) clearInterval(this._timer) } From 895aad88dc0a8a78ce1e60ee28f26b3d74701d26 Mon Sep 17 00:00:00 2001 From: olzzon Date: Wed, 27 Nov 2024 09:02:58 +0100 Subject: [PATCH 3/3] fix: remove .on() in discard() - typo --- src/Ember/Client/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Ember/Client/index.ts b/src/Ember/Client/index.ts index 4e7eb71..87ef528 100644 --- a/src/Ember/Client/index.ts +++ b/src/Ember/Client/index.ts @@ -170,10 +170,9 @@ export class EmberClient extends EventEmitter { this._client.removeAllListeners() // @ts-expect-error: after using this method, properties are no longer expected to always exist delete this._client - this._client.on('disconnected', () => { - this._requests.clear() // Just clean up the requests - this.emit('disconnected') // Notify listeners about the disconnection - }) + this._requests.clear() // Just clean up the requests + this.emit('disconnected') // Notify listeners about the disconnection + clearInterval(this._timer) }