From 62155ba0b79516141633b86765921b2401fcc2ed Mon Sep 17 00:00:00 2001 From: Denis Badurina Date: Fri, 28 Aug 2020 13:06:49 +0200 Subject: [PATCH] fix: notify only relevant sinks about errors or completions --- src/client.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index d96198d8..ab055e0f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -166,14 +166,12 @@ export function createClient(options: ClientOptions): Client { sink.complete(), ); } else { - // all other close events are considered erroneous for all sinks - // reading the `CloseEvent.reason` can either throw or empty the whole error message // (if trying to pass the reason in the `Error` message). having this in mind, // simply let the user handle the close event... - Object.entries(pendingSinks).forEach(([, sink]) => - sink.error(closeEvent), - ); + + // only the subscribed sinks should be errored out because + // the pending ones are probably waiting on a new socket Object.entries(subscribedSinks).forEach(([, sink]) => sink.error(closeEvent), ); @@ -216,10 +214,12 @@ export function createClient(options: ClientOptions): Client { } catch (err) { socky.dispose(); + // only pending sinks can error out here because opening a + // socket and receiving a connection ack message means + // all subscribed ones are disposed (or on a different socket) + // and we are now creating a fresh connection Object.entries(pendingSinks).forEach(([, sink]) => sink.error(err)); - Object.entries(subscribedSinks).forEach(([, sink]) => - sink.error(err), - ); + if (!done) { done = true; reject(err);