summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/shepherd.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-27 15:36:33 +0100
committerFlorian Dold <florian@dold.me>2024-02-27 15:36:33 +0100
commit7e5827eb4fbde75e109d68393145151901c7a8ea (patch)
tree852f39d499b96c2009459fdacf3185bb61f0dfbf /packages/taler-wallet-core/src/shepherd.ts
parentf78d7dc613946b0316a559aa0161dd02b056b05d (diff)
downloadwallet-core-7e5827eb4fbde75e109d68393145151901c7a8ea.tar.gz
wallet-core-7e5827eb4fbde75e109d68393145151901c7a8ea.tar.bz2
wallet-core-7e5827eb4fbde75e109d68393145151901c7a8ea.zip
-move state into shepherd
Diffstat (limited to 'packages/taler-wallet-core/src/shepherd.ts')
-rw-r--r--packages/taler-wallet-core/src/shepherd.ts23
1 files changed, 21 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/shepherd.ts b/packages/taler-wallet-core/src/shepherd.ts
index bf2f6b50f..ec0f6a76e 100644
--- a/packages/taler-wallet-core/src/shepherd.ts
+++ b/packages/taler-wallet-core/src/shepherd.ts
@@ -141,6 +141,8 @@ export class TaskScheduler {
private throttler = new TaskThrottler();
+ isRunning: boolean = false;
+
constructor(private ws: InternalWalletState) {}
async loadTasksFromDb(): Promise<void> {
@@ -153,9 +155,26 @@ export class TaskScheduler {
}
}
+ ensureRunning(): void {
+ if (this.isRunning) {
+ return;
+ }
+ this.run()
+ .catch((e) => {
+ logger.error("error running task loop");
+ logger.error(`err: ${e}`);
+ })
+ .then(() => {
+ logger.info("done running task loop");
+ });
+ }
+
async run(opts: RetryLoopOpts = {}): Promise<void> {
+ if (this.isRunning) {
+ throw Error("task loop already running");
+ }
logger.info("Running task loop.");
- this.ws.isTaskLoopRunning = true;
+ this.isRunning = true;
await this.loadTasksFromDb();
logger.info("loaded!");
logger.info(`sheps: ${this.sheps.size}`);
@@ -182,7 +201,7 @@ export class TaskScheduler {
}
await this.iterCond.wait();
}
- this.ws.isTaskLoopRunning = false;
+ this.isRunning = false;
logger.info("Done with task loop.");
}