diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-02-24 22:38:07 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-02-24 22:38:07 +0530 |
commit | 055685e78528aaf6b57ce70c4cc0221f5c0f37a3 (patch) | |
tree | ddcd42ebaaa439029a74452dabc4159ab3951f52 /src | |
parent | 644ad4e9bb5e7bbd3e74b842e45ef6056996b03b (diff) |
fall back to synchronous workers on old nodejs
Diffstat (limited to 'src')
-rw-r--r-- | src/headless/helpers.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/headless/helpers.ts b/src/headless/helpers.ts index 6832cd4f4..a5dad3856 100644 --- a/src/headless/helpers.ts +++ b/src/headless/helpers.ts @@ -34,6 +34,7 @@ import { WalletNotification, NotificationType } from "../types/notifications"; import { Database } from "../util/query"; import { NodeHttpLib } from "./NodeHttpLib"; import { Logger } from "../util/logging"; +import { SynchronousCryptoWorkerFactory } from "../crypto/workers/synchronousWorker"; const logger = new Logger("helpers.ts"); @@ -113,14 +114,19 @@ export async function getDefaultNodeWallet( const myDb = await openTalerDatabase(myIdbFactory, myVersionChange); - //const worker = new SynchronousCryptoWorkerFactory(); - //const worker = new NodeCryptoWorkerFactory(); - - const worker = new NodeThreadCryptoWorkerFactory(); + let workerFactory; + try { + // Try if we have worker threads available, fails in older node versions. + 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 w = new Wallet(dbWrap, myHttpLib, worker); + const w = new Wallet(dbWrap, myHttpLib, workerFactory); if (args.notifyHandler) { w.addNotificationListener(args.notifyHandler); } |