Skip to content

Commit

Permalink
[CORL-1243] Subscription Errors (#3074)
Browse files Browse the repository at this point in the history
* fix: fixed subscription event error

* fix: further subscription refinements

* fix: review fixes

* fix: exhastive deps

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
wyattjoh and kodiakhq[bot] committed Aug 6, 2020
1 parent 459e11a commit 6fabeb2
Show file tree
Hide file tree
Showing 15 changed files with 643 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default function createManagedSubscriptionClient(
cacheConfig,
observer,
};

request.subscribe = () => {
if (!subscriptionClient) {
subscriptionClient = new SubscriptionClient(url, {
Expand Down Expand Up @@ -165,14 +166,26 @@ export default function createManagedSubscriptionClient(
}
}

// When the subscription is disposed, this will be true.
let disposed = false;

return {
dispose: () => {
// Guard against double disposes. Multiple calls to dispose will now
// result in no-ops.
if (disposed) {
return;
}
disposed = true;

let closed = false;
const i = requests.findIndex((r) => r === request);
if (i !== -1) {
// Unsubscribe if available.
if (request.unsubscribe) {
request.unsubscribe();
}

// Remove from requests list.
requests.splice(i, 1);

Expand All @@ -182,6 +195,7 @@ export default function createManagedSubscriptionClient(
(requests.length === 0 || requests.every((r) => !r.unsubscribe))
) {
closeClient();
closed = true;
}
}

Expand All @@ -196,6 +210,12 @@ export default function createManagedSubscriptionClient(
"with variables:",
JSON.stringify(request.variables)
);

if (closed) {
window.console.debug(
"subscription client disconnecting, no more subscriptions being tracked"
);
}
}
},
};
Expand Down

0 comments on commit 6fabeb2

Please sign in to comment.