Added timeout argument to WorkerInterface.

This commit is contained in:
Mikunj 2018-12-17 09:55:51 +11:00
parent 6bcb259919
commit 3690f4acda
2 changed files with 5 additions and 3 deletions

View file

@ -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
);
});
};

View file

@ -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