diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-08-01 23:21:15 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-08-01 23:21:15 +0200 |
commit | 5f62d83a4ddab49a20ed29221c204dff5fe52b6d (patch) | |
tree | 8883706456b268f3a42ac64c21d987e3e908e13e /src/crypto/cryptoApi.ts | |
parent | 92b04858a3dcc98b8d252e69a06c8ee2f1745394 (diff) | |
download | wallet-core-5f62d83a4ddab49a20ed29221c204dff5fe52b6d.tar.xz |
headless/android port, PoC for CLI / headless tests
Diffstat (limited to 'src/crypto/cryptoApi.ts')
-rw-r--r-- | src/crypto/cryptoApi.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts index d3a93ff8d..5e3237836 100644 --- a/src/crypto/cryptoApi.ts +++ b/src/crypto/cryptoApi.ts @@ -41,6 +41,7 @@ import { BenchmarkResult, CoinWithDenom, PayCoinInfo } from "../walletTypes"; import * as timer from "../timer"; import { startWorker } from "./startWorker"; +import { throws } from "assert"; /** * State of a crypto worker. @@ -98,6 +99,11 @@ export class CryptoApi { */ private numBusy: number = 0; + /** + * Did we stop accepting new requests? + */ + private stopped: boolean = false; + public enableTracing = false; /** @@ -106,6 +112,7 @@ export class CryptoApi { terminateWorkers() { for (let worker of this.workers) { if (worker.w) { + this.enableTracing && console.log("terminating worker"); worker.w.terminate(); if (worker.terminationTimerHandle) { worker.terminationTimerHandle.clear(); @@ -120,10 +127,19 @@ export class CryptoApi { } } + stop() { + this.terminateWorkers(); + this.stopped = true; + } + /** * Start a worker (if not started) and set as busy. */ wake(ws: WorkerState, work: WorkItem): void { + if (this.stopped) { + this.enableTracing && console.log("not waking, as cryptoApi is stopped"); + return; + } if (ws.currentWorkItem !== null) { throw Error("assertion failed"); } @@ -158,7 +174,7 @@ export class CryptoApi { ws.w = null; } }; - ws.terminationTimerHandle = timer.after(5 * 1000, destroy); + ws.terminationTimerHandle = timer.after(15 * 1000, destroy); } handleWorkerError(ws: WorkerState, e: ErrorEvent) { @@ -253,6 +269,7 @@ export class CryptoApi { priority: number, ...args: any[] ): Promise<T> { + this.enableTracing && console.log("cryptoApi: doRpc called"); const p: Promise<T> = new Promise<T>((resolve, reject) => { const rpcId = this.nextRpcId++; const workItem: WorkItem = { |