From 3690f4acda71a26a0534432d075ee62ce327fcf4 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 17 Dec 2018 09:55:51 +1100 Subject: [PATCH] Added timeout argument to WorkerInterface. --- js/modules/util_worker_interface.js | 5 +++-- preload.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/js/modules/util_worker_interface.js b/js/modules/util_worker_interface.js index 1c7795887..79306516b 100644 --- a/js/modules/util_worker_interface.js +++ b/js/modules/util_worker_interface.js @@ -15,8 +15,9 @@ class TimedOutError extends Error { } class WorkerInterface { - constructor(path) { + constructor(path, timeout = WORKER_TIMEOUT) { this._utilWorker = new Worker(path); + this.timeout = timeout; this._jobs = Object.create(null); this._DEBUG = false; this._jobCounter = 0; @@ -112,7 +113,7 @@ class WorkerInterface { setTimeout( () => reject(new TimedOutError(`Worker job ${jobId} (${fnName}) timed out`)), - WORKER_TIMEOUT + this.timeout ); }); }; diff --git a/preload.js b/preload.js index d6b8924b3..e6942138a 100644 --- a/preload.js +++ b/preload.js @@ -269,8 +269,9 @@ window.LokiAPI = new LokiServer({ window.mnemonic = require('./libloki/mnemonic'); const { WorkerInterface } = require('./js/modules/util_worker_interface'); +// A Worker with a 3 minute timeout const utilWorkerPath = path.join(app.getAppPath(), 'js', 'util_worker.js'); -const utilWorker = new WorkerInterface(utilWorkerPath); +const utilWorker = new WorkerInterface(utilWorkerPath, 3 * 60 * 1000); window.callWorker = (fnName, ...args) => utilWorker.callWorker(fnName, ...args); // Linux seems to periodically let the event loop stop, so this is a global workaround