From 995f7cf0b4f4de4aea2482b399415176d4de3f9e Mon Sep 17 00:00:00 2001 From: Gancho Radkov Date: Thu, 11 Jan 2024 18:23:31 +0200 Subject: [PATCH] fix: uses unique watch label for each topic --- packages/core/src/controllers/subscriber.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/src/controllers/subscriber.ts b/packages/core/src/controllers/subscriber.ts index 3be3a0b48..e81f4ddb3 100644 --- a/packages/core/src/controllers/subscriber.ts +++ b/packages/core/src/controllers/subscriber.ts @@ -122,20 +122,20 @@ export class Subscriber extends ISubscriber { public isSubscribed: ISubscriber["isSubscribed"] = async (topic: string) => { // topic subscription is already resolved if (this.topics.includes(topic)) return true; - + const label = `${this.pendingSubscriptionWatchLabel}_${topic}`; // wait for the subscription to resolve const exists = await new Promise((resolve, reject) => { const watch = new Watch(); - watch.start(this.pendingSubscriptionWatchLabel); + watch.start(label); const interval = setInterval(() => { if (!this.pending.has(topic) && this.topics.includes(topic)) { clearInterval(interval); - watch.stop(this.pendingSubscriptionWatchLabel); + watch.stop(label); resolve(true); } - if (watch.elapsed(this.pendingSubscriptionWatchLabel) >= PENDING_SUB_RESOLUTION_TIMEOUT) { + if (watch.elapsed(label) >= PENDING_SUB_RESOLUTION_TIMEOUT) { clearInterval(interval); - watch.stop(this.pendingSubscriptionWatchLabel); + watch.stop(label); reject(new Error("Subscription resolution timeout")); } }, this.pollingInterval);