gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: -move state into shepherd


From: gnunet
Subject: [taler-wallet-core] branch master updated: -move state into shepherd
Date: Tue, 27 Feb 2024 15:36:37 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 7e5827eb4 -move state into shepherd
7e5827eb4 is described below

commit 7e5827eb4fbde75e109d68393145151901c7a8ea
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Feb 27 15:36:33 2024 +0100

    -move state into shepherd
---
 packages/taler-wallet-core/src/exchanges.ts    |  2 +-
 packages/taler-wallet-core/src/pay-merchant.ts |  3 +--
 packages/taler-wallet-core/src/shepherd.ts     | 23 +++++++++++++++++++++--
 packages/taler-wallet-core/src/testing.ts      | 12 ++++++------
 packages/taler-wallet-core/src/wallet.ts       | 17 -----------------
 5 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/packages/taler-wallet-core/src/exchanges.ts 
b/packages/taler-wallet-core/src/exchanges.ts
index 6095fadd5..0b7c65491 100644
--- a/packages/taler-wallet-core/src/exchanges.ts
+++ b/packages/taler-wallet-core/src/exchanges.ts
@@ -1082,7 +1082,7 @@ export async function fetchFreshExchange(
 ): Promise<ReadyExchangeSummary> {
   const canonUrl = canonicalizeBaseUrl(baseUrl);
 
-  ws.ensureTaskLoopRunning();
+  ws.taskScheduler.ensureRunning();
 
   await startUpdateExchangeEntry(ws, canonUrl, {
     forceUpdate: options.forceUpdate,
diff --git a/packages/taler-wallet-core/src/pay-merchant.ts 
b/packages/taler-wallet-core/src/pay-merchant.ts
index 332660ad5..73dc59ba2 100644
--- a/packages/taler-wallet-core/src/pay-merchant.ts
+++ b/packages/taler-wallet-core/src/pay-merchant.ts
@@ -1732,8 +1732,7 @@ async function waitPaymentResult(
 ): Promise<ConfirmPayResult> {
   const ctx = new PayMerchantTransactionContext(ws, proposalId);
 
-  ws.ensureTaskLoopRunning();
-
+  ws.taskScheduler.ensureRunning();
   ws.taskScheduler.startShepherdTask(ctx.taskId);
 
   // FIXME: Clean up using the new JS "using" / Symbol.dispose syntax.
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.");
   }
 
diff --git a/packages/taler-wallet-core/src/testing.ts 
b/packages/taler-wallet-core/src/testing.ts
index bcb6abca0..22af816e5 100644
--- a/packages/taler-wallet-core/src/testing.ts
+++ b/packages/taler-wallet-core/src/testing.ts
@@ -402,7 +402,7 @@ export async function waitUntilAllTransactionsFinal(
   ws: InternalWalletState,
 ): Promise<void> {
   logger.info("waiting until all transactions are in a final state");
-  ws.ensureTaskLoopRunning();
+  ws.taskScheduler.ensureRunning();
   let p: OpenedPromise<void> | undefined = undefined;
   const cancelNotifs = ws.addNotificationListener((notif) => {
     if (!p) {
@@ -462,7 +462,7 @@ export async function waitUntilGivenTransactionsFinal(
   if (transactionIds.length === 0) {
     return;
   }
-  ws.ensureTaskLoopRunning();
+  ws.taskScheduler.ensureRunning();
   const txIdSet = new Set(transactionIds);
   let p: OpenedPromise<void> | undefined = undefined;
   const cancelNotifs = ws.addNotificationListener((notif) => {
@@ -522,7 +522,7 @@ export async function waitUntilRefreshesDone(
   ws: InternalWalletState,
 ): Promise<void> {
   logger.info("waiting until all refresh transactions are in a final state");
-  ws.ensureTaskLoopRunning();
+  ws.taskScheduler.ensureRunning();
   let p: OpenedPromise<void> | undefined = undefined;
   const cancelNotifs = ws.addNotificationListener((notif) => {
     if (!p) {
@@ -576,7 +576,7 @@ async function waitUntilTransactionPendingReady(
   transactionId: string,
 ): Promise<void> {
   logger.info(`starting waiting for ${transactionId} to be in pending(ready)`);
-  ws.ensureTaskLoopRunning();
+  ws.taskScheduler.ensureRunning();
   let p: OpenedPromise<void> | undefined = undefined;
   const cancelNotifs = ws.addNotificationListener((notif) => {
     if (!p) {
@@ -617,7 +617,7 @@ export async function waitTransactionState(
       txState,
     )})`,
   );
-  ws.ensureTaskLoopRunning();
+  ws.taskScheduler.ensureRunning();
   let p: OpenedPromise<void> | undefined = undefined;
   const cancelNotifs = ws.addNotificationListener((notif) => {
     if (!p) {
@@ -669,7 +669,7 @@ export async function runIntegrationTest2(
   ws: InternalWalletState,
   args: IntegrationTestV2Args,
 ): Promise<void> {
-  ws.ensureTaskLoopRunning();
+  ws.taskScheduler.ensureRunning();
   logger.info("running test with arguments", args);
 
   const exchangeInfo = await fetchFreshExchange(ws, args.exchangeBaseUrl);
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 79f7a1be5..bab054f4b 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -1486,8 +1486,6 @@ export class InternalWalletState {
    */
   private resourceLocks: Set<string> = new Set();
 
-  isTaskLoopRunning: boolean = false;
-
   taskScheduler: TaskScheduler = new TaskScheduler(this);
 
   config: Readonly<WalletConfig>;
@@ -1604,21 +1602,6 @@ export class InternalWalletState {
       }
     }
   }
-
-  ensureTaskLoopRunning(): void {
-    if (this.isTaskLoopRunning) {
-      return;
-    }
-    this.taskScheduler
-      .run()
-      .catch((e) => {
-        logger.error("error running task loop");
-        logger.error(`err: ${e}`);
-      })
-      .then(() => {
-        logger.info("done running task loop");
-      });
-  }
 }
 
 /**

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]