Added timeout argument to WorkerInterface.

pull/115/head
Mikunj 6 years ago
parent 6bcb259919
commit 3690f4acda

@ -15,8 +15,9 @@ class TimedOutError extends Error {
} }
class WorkerInterface { class WorkerInterface {
constructor(path) { constructor(path, timeout = WORKER_TIMEOUT) {
this._utilWorker = new Worker(path); this._utilWorker = new Worker(path);
this.timeout = timeout;
this._jobs = Object.create(null); this._jobs = Object.create(null);
this._DEBUG = false; this._DEBUG = false;
this._jobCounter = 0; this._jobCounter = 0;
@ -112,7 +113,7 @@ class WorkerInterface {
setTimeout( setTimeout(
() => reject(new TimedOutError(`Worker job ${jobId} (${fnName}) timed out`)), () => reject(new TimedOutError(`Worker job ${jobId} (${fnName}) timed out`)),
WORKER_TIMEOUT this.timeout
); );
}); });
}; };

@ -269,8 +269,9 @@ window.LokiAPI = new LokiServer({
window.mnemonic = require('./libloki/mnemonic'); window.mnemonic = require('./libloki/mnemonic');
const { WorkerInterface } = require('./js/modules/util_worker_interface'); 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 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); window.callWorker = (fnName, ...args) => utilWorker.callWorker(fnName, ...args);
// Linux seems to periodically let the event loop stop, so this is a global workaround // Linux seems to periodically let the event loop stop, so this is a global workaround

Loading…
Cancel
Save