aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-08-01 23:21:15 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-08-01 23:21:15 +0200
commit5f62d83a4ddab49a20ed29221c204dff5fe52b6d (patch)
tree8883706456b268f3a42ac64c21d987e3e908e13e /src/crypto
parent92b04858a3dcc98b8d252e69a06c8ee2f1745394 (diff)
headless/android port, PoC for CLI / headless tests
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/cryptoApi.ts19
-rw-r--r--src/crypto/nodeWorker.ts1
2 files changed, 19 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 = {
diff --git a/src/crypto/nodeWorker.ts b/src/crypto/nodeWorker.ts
index fa942387a..b5a2e8b44 100644
--- a/src/crypto/nodeWorker.ts
+++ b/src/crypto/nodeWorker.ts
@@ -92,6 +92,7 @@ export class Worker {
* Forcibly terminate the worker thread.
*/
terminate () {
+ console.log("terminating node.js worker");
this.child.kill("SIGINT");
}
}