Use detailed presence information from SplatNet 3

This commit is contained in:
Samuel Elliott
2022-09-21 15:47:42 +01:00
parent e5fe9b389e
commit 4e6a29f74f
11 changed files with 575 additions and 18 deletions

View File

@@ -64,3 +64,44 @@ export enum LoopResult {
OK = LoopRunOk as any,
OK_SKIP_INTERVAL = LoopRunOkSkipInterval as any,
}
export abstract class EmbeddedLoop extends Loop {
onStop?(): Promise<void> | void;
enable() {
if (this._running !== 0) return;
this._run();
}
disable() {
this._running = 0;
}
get enabled() {
return this._running !== 0;
}
private _running = 0;
private async _run() {
this._running++;
const i = this._running;
try {
await this.loop(true);
while (i === this._running) {
await this.loop();
}
if (this._running === 0 && !this.onStop) {
// Run one more time after the loop ends
const result = await this.loopRun();
}
await this.onStop?.();
} finally {
this._running = 0;
}
}
}