diff options
author | Florian Dold <florian@dold.me> | 2023-06-30 23:01:48 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-06-30 23:01:48 +0200 |
commit | 7a18e12a175856b3d17d2bb70ec549004c281ff5 (patch) | |
tree | 73b753a55458774aa646356c3d09ac1417458696 /packages/taler-wallet-core/src/wallet.ts | |
parent | 86e9799ffdfa5aab5a25cbce1d18881e0a3dfc3e (diff) | |
download | wallet-core-7a18e12a175856b3d17d2bb70ec549004c281ff5.tar.xz |
wallet-core: towards event-based waiting in runIntegrationTestV2
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 583dc33d4..1b355a32c 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -287,9 +287,7 @@ import { GetReadOnlyAccess, GetReadWriteAccess, } from "./util/query.js"; -import { - TaskIdentifiers, -} from "./operations/common.js"; +import { TaskIdentifiers } from "./operations/common.js"; import { TimerAPI, TimerGroup } from "./util/timer.js"; import { WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, @@ -404,6 +402,12 @@ async function runTaskLoop( opts: RetryLoopOpts = {}, ): Promise<TaskLoopResult> { logger.info(`running task loop opts=${j2s(opts)}`); + if (ws.isTaskLoopRunning) { + logger.warn( + "task loop already running, nesting the wallet-core task loop is deprecated and should be avoided", + ); + } + ws.isTaskLoopRunning = true; let retriesExceeded = false; for (let iteration = 0; !ws.stopped; iteration++) { const pending = await getPendingOperations(ws); @@ -434,6 +438,14 @@ async function runTaskLoop( if (opts.stopWhenDone && numGivingLiveness === 0 && iteration !== 0) { logger.warn(`stopping, as no pending operations have lifeness`); + ws.isTaskLoopRunning = false; + return { + retriesExceeded, + }; + } + + if (ws.stopped) { + ws.isTaskLoopRunning = false; return { retriesExceeded, }; @@ -468,16 +480,24 @@ async function runTaskLoop( } await runTaskWithErrorReporting(ws, p.id, async () => { logger.trace(`running pending ${JSON.stringify(p, undefined, 2)}`); + ws.isTaskLoopRunning = false; return await callOperationHandler(ws, p); }); ws.notify({ type: NotificationType.PendingOperationProcessed, id: p.id, }); + if (ws.stopped) { + ws.isTaskLoopRunning = false; + return { + retriesExceeded, + }; + } } } } - logger.trace("exiting wallet retry loop"); + logger.trace("exiting wallet task loop"); + ws.isTaskLoopRunning = false; return { retriesExceeded, }; @@ -1575,7 +1595,9 @@ export async function handleCoreApiRequest( }; } catch (e: any) { const err = getErrorDetailFromException(e); - logger.info(`finished wallet core request ${operation} with error: ${j2s(err)}`); + logger.info( + `finished wallet core request ${operation} with error: ${j2s(err)}`, + ); return { type: "error", operation, @@ -1737,6 +1759,8 @@ class InternalWalletStateImpl implements InternalWalletState { */ private resourceLocks: Set<string> = new Set(); + isTaskLoopRunning: boolean = false; + config: Readonly<WalletConfig>; constructor( @@ -1948,6 +1972,20 @@ class InternalWalletStateImpl implements InternalWalletState { } } } + + ensureTaskLoopRunning(): void { + if (this.isTaskLoopRunning) { + return; + } + runTaskLoop(this) + .catch((e) => { + logger.error("error running task loop"); + logger.error(`err: ${e}`); + }) + .then(() => { + logger.info("done running task loop"); + }); + } } /** |