Skip to content

Commit

Permalink
only stop listeners that exist at the time
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Jan 2, 2024
1 parent 4b57621 commit e1ec11c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/meteor/app/utils/client/lib/SDKClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ const createStreamManager = () => {
// We have to delete the stream first because waiting for the unsublist causes a race condition
// when trying to create a new stream right after stopping the old one.
const unsubList = proxyUnsubLists.get(`${streamName}/${key}`);
// turning the set into an array to avoid stopping events registered on a new stream
const unsubArray = unsubList ? Array.from(unsubList) : [];
const streamLiteral = `stream-${streamName}/${key}`;
const unsubscribe = streams.get(streamLiteral);
if (unsubscribe) {
unsubscribe();
streams.delete(streamLiteral);
}
unsubList?.forEach((stop) => stop());
unsubArray.forEach((stop) => stop());
};

return { stream, stopAll };
Expand Down

0 comments on commit e1ec11c

Please sign in to comment.