fall back to synchronous workers on old nodejs

This commit is contained in:
Florian Dold 2020-02-24 22:38:07 +05:30
parent 644ad4e9bb
commit 055685e785
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "taler-wallet", "name": "taler-wallet",
"version": "0.6.8", "version": "0.6.9",
"description": "", "description": "",
"main": "dist/node/index.js", "main": "dist/node/index.js",
"repository": { "repository": {

View File

@ -34,6 +34,7 @@ import { WalletNotification, NotificationType } from "../types/notifications";
import { Database } from "../util/query"; import { Database } from "../util/query";
import { NodeHttpLib } from "./NodeHttpLib"; import { NodeHttpLib } from "./NodeHttpLib";
import { Logger } from "../util/logging"; import { Logger } from "../util/logging";
import { SynchronousCryptoWorkerFactory } from "../crypto/workers/synchronousWorker";
const logger = new Logger("helpers.ts"); const logger = new Logger("helpers.ts");
@ -113,14 +114,19 @@ export async function getDefaultNodeWallet(
const myDb = await openTalerDatabase(myIdbFactory, myVersionChange); const myDb = await openTalerDatabase(myIdbFactory, myVersionChange);
//const worker = new SynchronousCryptoWorkerFactory(); let workerFactory;
//const worker = new NodeCryptoWorkerFactory(); try {
// Try if we have worker threads available, fails in older node versions.
const worker = new NodeThreadCryptoWorkerFactory(); require("worker_threads")
workerFactory = new NodeThreadCryptoWorkerFactory();
} catch (e) {
console.log("worker threads not available, falling back to synchronous workers");
workerFactory = new SynchronousCryptoWorkerFactory();
}
const dbWrap = new Database(myDb); const dbWrap = new Database(myDb);
const w = new Wallet(dbWrap, myHttpLib, worker); const w = new Wallet(dbWrap, myHttpLib, workerFactory);
if (args.notifyHandler) { if (args.notifyHandler) {
w.addNotificationListener(args.notifyHandler); w.addNotificationListener(args.notifyHandler);
} }