make timeoutMs a settable property

This commit is contained in:
2025-04-11 16:57:47 -07:00
parent 6cc20a4a6a
commit 44095e711a
2 changed files with 7 additions and 18 deletions

View File

@@ -1,27 +1,16 @@
import { RepositoryLoader } from "./RepositoryLoader";
// Ideas to break this into smaller pieces in the future:
// Have one repository data loader running for each supported system
// Each data loader independently updates data based on frequency of usage
// Notes on this: we only need to reload ETA data frequently
// Other data can be reloaded periodically
// Detailed list:
// - ETA: reload frequently or switch to write-through approach
// - Shuttles: reload every minute
// - Routes: reload every few minutes
// - Stops: reload every few minutes
// - OrderedStops: reload every few minutes
// - Systems: reload once a day
// To break down timed loading in the future:
// Add flags to the repository indicating which data users are subscribed to
// In the loader's `fetchAll` method, check flags and update only needed data
export class TimedApiBasedRepositoryLoader {
private shouldBeRunning: boolean = false;
private timer: any;
readonly timeout = 10000;
constructor(
public loader: RepositoryLoader,
public timeoutMs: number = 10000,
) {
this.startFetchDataAndUpdate = this.startFetchDataAndUpdate.bind(this);
}
@@ -49,6 +38,6 @@ export class TimedApiBasedRepositoryLoader {
console.error(e);
}
this.timer = setTimeout(this.startFetchDataAndUpdate, this.timeout);
this.timer = setTimeout(this.startFetchDataAndUpdate, this.timeoutMs);
}
}