Skip to content

Commit

Permalink
fix: notify only relevant sinks about errors or completions
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Aug 28, 2020
1 parent b45b38f commit 62155ba
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 62155ba

Please sign in to comment.