add start and stop methods, move subscribe out of constructor

This commit is contained in:
2025-03-31 19:17:41 -07:00
parent 02b3b77a61
commit ef94055133

View File

@@ -18,8 +18,6 @@ export class ETANotificationScheduler {
this.etaSubscriberCallback = this.etaSubscriberCallback.bind(this); this.etaSubscriberCallback = this.etaSubscriberCallback.bind(this);
this.sendEtaNotificationImmediately = this.sendEtaNotificationImmediately.bind(this); this.sendEtaNotificationImmediately = this.sendEtaNotificationImmediately.bind(this);
this.sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold = this.sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold.bind(this); this.sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold = this.sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold.bind(this);
this.shuttleRepository.subscribeToEtaUpdates(this.etaSubscriberCallback);
} }
private async sendEtaNotificationImmediately(notificationData: ScheduledNotification): Promise<boolean> { private async sendEtaNotificationImmediately(notificationData: ScheduledNotification): Promise<boolean> {
@@ -81,4 +79,13 @@ export class ETANotificationScheduler {
return await this.sendEtaNotificationImmediately(notificationObject); 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);
}
} }