diff --git a/src/WorkerHandler.js b/src/WorkerHandler.js index 8f571f44..9bf4ed53 100644 --- a/src/WorkerHandler.js +++ b/src/WorkerHandler.js @@ -222,9 +222,9 @@ function handleEmittedStdPayload(handler, payload) { // TODO: refactor if parallel task execution gets added Object.values(handler.processing) .forEach(task => task?.options?.on(payload)); - + Object.values(handler.tracking) - .forEach(task => task?.options?.on(payload)); + .forEach(task => task?.options?.on(payload)); } /** @@ -306,7 +306,7 @@ function WorkerHandler(script, _options) { task.options.on(response.payload); } } - } + } } if (response.method === CLEANUP_METHOD_ID) { @@ -335,7 +335,7 @@ function WorkerHandler(script, _options) { me.processing[id].resolver.reject(error); } } - + me.processing = Object.create(null); } @@ -438,7 +438,7 @@ WorkerHandler.prototype.exec = function(method, params, resolver, options) { options: options, error, }; - + // remove this task from the queue. It is already rejected (hence this // catch event), and else it will be rejected again when terminating delete me.processing[id]; @@ -454,7 +454,7 @@ WorkerHandler.prototype.exec = function(method, params, resolver, options) { } var promise = me.terminateAndNotify(true) - .then(function() { + .then(function() { throw err; }, function(err) { throw err; @@ -462,23 +462,23 @@ WorkerHandler.prototype.exec = function(method, params, resolver, options) { return promise; }); - + me.worker.send({ id, - method: CLEANUP_METHOD_ID + method: CLEANUP_METHOD_ID }); - - + + /** * Sets a timeout to reject the cleanup operation if the message sent to the worker * does not receive a response. see worker.tryCleanup for worker cleanup operations. * Here we use the workerTerminateTimeout as the worker will be terminated if the timeout does invoke. - * + * * We need this timeout in either case of a Timeout or Cancellation Error as if * the worker does not send a message we still need to give a window of time for a response. - * - * The workerTermniateTimeout is used here if this promise is rejected the worker cleanup - * operations will occure. + * + * The workerTerminateTimeout is used here if this promise is rejected the worker cleanup + * operations will occur. */ me.tracking[id].timeoutId = setTimeout(function() { me.tracking[id].resolver.reject(error); @@ -625,7 +625,7 @@ WorkerHandler.prototype.terminateAndNotify = function (force, timeout) { }; /** -* Wrapper error type to denote that a TimeoutError has already been proceesed +* Wrapper error type to denote that a TimeoutError has already been processed * and we should skip cleanup operations * @param {Promise.TimeoutError} timeoutError */ @@ -653,4 +653,3 @@ module.exports._setupBrowserWorker = setupBrowserWorker; module.exports._setupWorkerThreadWorker = setupWorkerThreadWorker; module.exports.ensureWorkerThreads = ensureWorkerThreads; module.exports.TerminateError = TerminateError - diff --git a/src/worker.js b/src/worker.js index b82b9cbd..c3f967ef 100644 --- a/src/worker.js +++ b/src/worker.js @@ -16,7 +16,7 @@ var Promise = require('./Promise').Promise; var TERMINATE_METHOD_ID = '__workerpool-terminate__'; /** - * Special message by parent which causes a child process worker to perform cleaup + * Special message by parent which causes a child process worker to perform cleanup * steps before determining if the child process worker should be terminated. */ var CLEANUP_METHOD_ID = '__workerpool-cleanup__'; @@ -35,7 +35,7 @@ var worker = { // works in both node.js and the browser var publicWorker = { /** - * Registers listeners which will trigger when a task is timed out or cancled. If all listeners resolve, the worker executing the given task will not be terminated. + * Registers listeners which will trigger when a task is timed out or canceled. If all listeners resolve, the worker executing the given task will not be terminated. * *Note*: If there is a blocking operation within a listener, the worker will be terminated. * @param {() => Promise} listener */ @@ -217,11 +217,11 @@ worker.cleanup = function(requestId) { let timerId; const timeoutPromise = new Promise((_resolve, reject) => { timerId = setTimeout(function () { - reject(new Error('Timeout occured waiting for abort handler, killing worker')); + reject(new Error('Timeout occurred waiting for abort handler, killing worker')); }, worker.abortListenerTimeout); }); - // Once a promise settles we need to clear the timeout to prevet fulfulling the promise twice + // Once a promise settles we need to clear the timeout to prevent fulfilling the promise twice const settlePromise = Promise.all(promises).then(function() { clearTimeout(timerId); _abort(); diff --git a/test/Pool.test.js b/test/Pool.test.js index 3f34da15..ff69daf0 100644 --- a/test/Pool.test.js +++ b/test/Pool.test.js @@ -188,7 +188,7 @@ describe('Pool', function () { assert(terminatedWorkers.includes('env_value2'), 'terminatedWorkers should include the value with counter = 2'); }); }); - + it('supports stdout/stderr capture via fork', function(done) { var pool = createPool(__dirname + '/workers/console.js', {workerType: 'process', emitStdStreams: true}); @@ -1558,7 +1558,7 @@ describe('Pool', function () { }); }); - + describe('abort handler', () => { it('should not terminate worker if abort listener is defined dedicated worker with Timeout', function () { var workerCount = 0; @@ -1568,7 +1568,7 @@ describe('Pool', function () { workerCount += 1; } }); - + return pool.exec('asyncTimeout', []) .timeout(200) .catch(function (err) { @@ -1578,8 +1578,8 @@ describe('Pool', function () { assert.strictEqual(stats.totalWorkers, 1); assert.strictEqual(stats.idleWorkers, 1); assert.strictEqual(stats.busyWorkers, 0); - }).then(function() { - return pool.exec(add, [1, 2]) + }).then(function() { + return pool.exec(add, [1, 2]) }).then(function() { var stats = pool.stats(); assert.strictEqual(workerCount, 1); @@ -1598,12 +1598,12 @@ describe('Pool', function () { workerCount += 1; }, }); - + let task = pool.exec('asyncTimeout', [], {}); // Wrap in a new promise which waits 50ms // in order to allow the function executing in the - // worker to + // worker to execute to termination return new Promise(function(resolve) { setTimeout(function() { resolve(); @@ -1618,8 +1618,8 @@ describe('Pool', function () { assert.strictEqual(stats.totalWorkers, 1); assert.strictEqual(stats.idleWorkers, 1); assert.strictEqual(stats.busyWorkers, 0); - }).then(function() { - return pool.exec(add, [1, 2]) + }).then(function() { + return pool.exec(add, [1, 2]) }).then(function() { var stats = pool.stats(); assert.strictEqual(workerCount, 1); @@ -1645,7 +1645,7 @@ describe('Pool', function () { return new Promise(function () { let timeout = setTimeout(function() { resolve(); - }, 5000); + }, 5000); me.worker.addAbortListener(function () { return new Promise(function (resolve) { clearTimeout(timeout); @@ -1673,7 +1673,7 @@ describe('Pool', function () { assert.strictEqual(stats.idleWorkers, 1); assert.strictEqual(stats.busyWorkers, 0); - }); + }); }); }); @@ -1691,7 +1691,7 @@ describe('Pool', function () { return new Promise(function (_resolve, reject) { let timeout = setTimeout(function() { reject(new Error("should not be thrown")); - }, 5000); + }, 5000); me.worker.addAbortListener(function () { return new Promise(function (resolve) { clearTimeout(timeout); @@ -1723,7 +1723,7 @@ describe('Pool', function () { assert.strictEqual(stats.idleWorkers, 1); assert.strictEqual(stats.busyWorkers, 0); - }); + }); }); }); @@ -1782,14 +1782,14 @@ describe('Pool', function () { done(); } }); - + const task = pool.exec('asyncAbortHandlerNeverResolves', []) const _ = new Promise(function(resolve) { setTimeout(function() { resolve(); }, 50); - }).then(function() { + }).then(function() { return task.cancel() .catch(function (err) { assert(err instanceof Promise.TimeoutError); @@ -1818,7 +1818,7 @@ describe('Pool', function () { var pool = createPool(__dirname + '/workers/cleanup-abort.js', { maxWorkers: 1, workerType: 'process', - emitStdStreams: true, + emitStdStreams: true, workerTerminateTimeout: 1000, }); @@ -1835,7 +1835,7 @@ describe('Pool', function () { var pool = createPool(__dirname + '/workers/cleanup-abort.js', { maxWorkers: 1, workerType: 'process', - emitStdStreams: true, + emitStdStreams: true, workerTerminateTimeout: 1000, });