From 2b4269077bb5eb696f020d9f16a3b14b60c6a5e0 Mon Sep 17 00:00:00 2001 From: Andreas Weber Date: Sun, 10 Sep 2023 20:49:55 +0200 Subject: [PATCH] fix: resolve connect Promise on close before open (AnWeber/httpbook#96) --- CHANGELOG.md | 4 ++++ src/plugins/websocket/websocketRequestClient.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26e00fff..53aac2d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [unreleased] + +- resolve connect Promise in Websocket Requests on close before open Connection () + ## [6.6.5] (2023-09-06) ### Fixes diff --git a/src/plugins/websocket/websocketRequestClient.ts b/src/plugins/websocket/websocketRequestClient.ts index 5c15c0a8..3de791fe 100644 --- a/src/plugins/websocket/websocketRequestClient.ts +++ b/src/plugins/websocket/websocketRequestClient.ts @@ -46,9 +46,13 @@ export class WebsocketRequestClient extends models.AbstractRequestClient(resolve => { - this._nativeClient?.on('open', () => { + const resolveListener = () => { resolve(); - }); + this.nativeClient?.off('open', resolveListener); + this.nativeClient?.off('close', resolveListener); + }; + this._nativeClient?.on('open', resolveListener); + this._nativeClient?.on('close', resolveListener); }); } } @@ -134,7 +138,7 @@ export class WebsocketRequestClient extends models.AbstractRequestClient