From ef94055133825af8d767ca92402186c48751b1bf Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 31 Mar 2025 19:17:41 -0700 Subject: [PATCH] add start and stop methods, move subscribe out of constructor --- .../schedulers/ETANotificationScheduler.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/notifications/schedulers/ETANotificationScheduler.ts b/src/notifications/schedulers/ETANotificationScheduler.ts index 943b74d..98a16a2 100644 --- a/src/notifications/schedulers/ETANotificationScheduler.ts +++ b/src/notifications/schedulers/ETANotificationScheduler.ts @@ -18,8 +18,6 @@ export class ETANotificationScheduler { this.etaSubscriberCallback = this.etaSubscriberCallback.bind(this); this.sendEtaNotificationImmediately = this.sendEtaNotificationImmediately.bind(this); this.sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold = this.sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold.bind(this); - - this.shuttleRepository.subscribeToEtaUpdates(this.etaSubscriberCallback); } private async sendEtaNotificationImmediately(notificationData: ScheduledNotification): Promise { @@ -81,4 +79,13 @@ export class ETANotificationScheduler { return await this.sendEtaNotificationImmediately(notificationObject); } + + // The following is a workaround for the constructor being called twice + public startListeningForUpdates() { + this.shuttleRepository.subscribeToEtaUpdates(this.etaSubscriberCallback); + } + + public stopListeningForUpdates() { + this.shuttleRepository.subscribeToEtaUpdates(this.etaSubscriberCallback); + } }