Skip to content

Commit

Permalink
fix: uses unique watch label for each topic
Browse files Browse the repository at this point in the history
  • Loading branch information
Gancho Radkov committed Jan 11, 2024
1 parent 01e3cbd commit 995f7cf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/controllers/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>((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);
Expand Down

0 comments on commit 995f7cf

Please sign in to comment.