1 line
76 KiB
Plaintext
1 line
76 KiB
Plaintext
{"version":3,"file":"workerpool.min.js","sources":["../src/environment.js","../src/Promise.js","../src/validateOptions.js","../src/WorkerHandler.js","../src/generated/embeddedWorker.js","../src/Pool.js","../src/debug-port-allocator.js","../src/transfer.js","../src/worker.js","../src/index.js"],"sourcesContent":["\n// source: https://github.com/flexdinesh/browser-or-node\n// source: https://github.com/mozilla/pdf.js/blob/7ea0e40e588864cd938d1836ec61f1928d3877d3/src/shared/util.js#L24\nvar isNode = function (nodeProcess) {\n return (\n typeof nodeProcess !== 'undefined' &&\n nodeProcess.versions != null &&\n nodeProcess.versions.node != null &&\n nodeProcess + '' === '[object process]'\n );\n}\nmodule.exports.isNode = isNode\n\n// determines the JavaScript platform: browser or node\nmodule.exports.platform = typeof process !== 'undefined' && isNode(process)\n ? 'node'\n : 'browser';\n\n// determines whether the code is running in main thread or not\n// note that in node.js we have to check both worker_thread and child_process\nvar worker_threads = module.exports.platform === 'node' && require('worker_threads');\nmodule.exports.isMainThread = module.exports.platform === 'node'\n ? ((!worker_threads || worker_threads.isMainThread) && !process.connected)\n : typeof Window !== 'undefined';\n\n// determines the number of cpus available\nmodule.exports.cpus = module.exports.platform === 'browser'\n ? self.navigator.hardwareConcurrency\n : require('os').cpus().length;\n\n","'use strict';\n\n/**\n * Promise\n *\n * Inspired by https://gist.github.com/RubaXa/8501359 from RubaXa <trash@rubaxa.org>\n * @template T\n * @template [E=Error]\n * @param {Function} handler Called as handler(resolve: Function, reject: Function)\n * @param {Promise} [parent] Parent promise for propagation of cancel and timeout\n */\nfunction Promise(handler, parent) {\n var me = this;\n\n if (!(this instanceof Promise)) {\n throw new SyntaxError('Constructor must be called with the new operator');\n }\n\n if (typeof handler !== 'function') {\n throw new SyntaxError('Function parameter handler(resolve, reject) missing');\n }\n\n var _onSuccess = [];\n var _onFail = [];\n\n // status\n /**\n * @readonly\n */\n this.resolved = false;\n /**\n * @readonly\n */\n this.rejected = false;\n /**\n * @readonly\n */\n this.pending = true;\n\n /**\n * Process onSuccess and onFail callbacks: add them to the queue.\n * Once the promise is resolved, the function _promise is replace.\n * @param {Function} onSuccess\n * @param {Function} onFail\n * @private\n */\n var _process = function (onSuccess, onFail) {\n _onSuccess.push(onSuccess);\n _onFail.push(onFail);\n };\n\n /**\n * Add an onSuccess callback and optionally an onFail callback to the Promise\n * @template TT\n * @template [TE=never]\n * @param {(r: T) => TT | PromiseLike<TT>} onSuccess\n * @param {(r: E) => TE | PromiseLike<TE>} [onFail]\n * @returns {Promise<TT | TE, any>} promise\n */\n this.then = function (onSuccess, onFail) {\n return new Promise(function (resolve, reject) {\n var s = onSuccess ? _then(onSuccess, resolve, reject) : resolve;\n var f = onFail ? _then(onFail, resolve, reject) : reject;\n\n _process(s, f);\n }, me);\n };\n\n /**\n * Resolve the promise\n * @param {*} result\n * @type {Function}\n */\n var _resolve = function (result) {\n // update status\n me.resolved = true;\n me.rejected = false;\n me.pending = false;\n\n _onSuccess.forEach(function (fn) {\n fn(result);\n });\n\n _process = function (onSuccess, onFail) {\n onSuccess(result);\n };\n\n _resolve = _reject = function () { };\n\n return me;\n };\n\n /**\n * Reject the promise\n * @param {Error} error\n * @type {Function}\n */\n var _reject = function (error) {\n // update status\n me.resolved = false;\n me.rejected = true;\n me.pending = false;\n\n _onFail.forEach(function (fn) {\n fn(error);\n });\n\n _process = function (onSuccess, onFail) {\n onFail(error);\n };\n\n _resolve = _reject = function () { }\n\n return me;\n };\n\n /**\n * Cancel the promise. This will reject the promise with a CancellationError\n * @returns {this} self\n */\n this.cancel = function () {\n if (parent) {\n parent.cancel();\n }\n else {\n _reject(new CancellationError());\n }\n\n return me;\n };\n\n /**\n * Set a timeout for the promise. If the promise is not resolved within\n * the time, the promise will be cancelled and a TimeoutError is thrown.\n * If the promise is resolved in time, the timeout is removed.\n * @param {number} delay Delay in milliseconds\n * @returns {this} self\n */\n this.timeout = function (delay) {\n if (parent) {\n parent.timeout(delay);\n }\n else {\n var timer = setTimeout(function () {\n _reject(new TimeoutError('Promise timed out after ' + delay + ' ms'));\n }, delay);\n\n me.always(function () {\n clearTimeout(timer);\n });\n }\n\n return me;\n };\n\n // attach handler passing the resolve and reject functions\n handler(function (result) {\n _resolve(result);\n }, function (error) {\n _reject(error);\n });\n}\n\n/**\n * Execute given callback, then call resolve/reject based on the returned result\n * @param {Function} callback\n * @param {Function} resolve\n * @param {Function} reject\n * @returns {Function}\n * @private\n */\nfunction _then(callback, resolve, reject) {\n return function (result) {\n try {\n var res = callback(result);\n if (res && typeof res.then === 'function' && typeof res['catch'] === 'function') {\n // method returned a promise\n res.then(resolve, reject);\n }\n else {\n resolve(res);\n }\n }\n catch (error) {\n reject(error);\n }\n }\n}\n\n/**\n * Add an onFail callback to the Promise\n * @template TT\n * @param {(error: E) => TT | PromiseLike<TT>} onFail\n * @returns {Promise<T | TT>} promise\n */\nPromise.prototype['catch'] = function (onFail) {\n return this.then(null, onFail);\n};\n\n// TODO: add support for Promise.catch(Error, callback)\n// TODO: add support for Promise.catch(Error, Error, callback)\n\n/**\n * Execute given callback when the promise either resolves or rejects.\n * @template TT\n * @param {() => Promise<TT>} fn\n * @returns {Promise<TT>} promise\n */\nPromise.prototype.always = function (fn) {\n return this.then(fn, fn);\n};\n\n/**\n * Create a promise which resolves when all provided promises are resolved,\n * and fails when any of the promises resolves.\n * @param {Promise[]} promises\n * @returns {Promise<any[], any>} promise\n */\nPromise.all = function (promises){\n return new Promise(function (resolve, reject) {\n var remaining = promises.length,\n results = [];\n\n if (remaining) {\n promises.forEach(function (p, i) {\n p.then(function (result) {\n results[i] = result;\n remaining--;\n if (remaining == 0) {\n resolve(results);\n }\n }, function (error) {\n remaining = 0;\n reject(error);\n });\n });\n }\n else {\n resolve(results);\n }\n });\n};\n\n/**\n * Create a promise resolver\n * @returns {{promise: Promise, resolve: Function, reject: Function}} resolver\n */\nPromise.defer = function () {\n var resolver = {};\n\n resolver.promise = new Promise(function (resolve, reject) {\n resolver.resolve = resolve;\n resolver.reject = reject;\n });\n\n return resolver;\n};\n\n/**\n * Create a cancellation error\n * @param {String} [message]\n * @extends Error\n */\nfunction CancellationError(message) {\n this.message = message || 'promise cancelled';\n this.stack = (new Error()).stack;\n}\n\nCancellationError.prototype = new Error();\nCancellationError.prototype.constructor = Error;\nCancellationError.prototype.name = 'CancellationError';\n\nPromise.CancellationError = CancellationError;\n\n\n/**\n * Create a timeout error\n * @param {String} [message]\n * @extends Error\n */\nfunction TimeoutError(message) {\n this.message = message || 'timeout exceeded';\n this.stack = (new Error()).stack;\n}\n\nTimeoutError.prototype = new Error();\nTimeoutError.prototype.constructor = Error;\nTimeoutError.prototype.name = 'TimeoutError';\n\nPromise.TimeoutError = TimeoutError;\n\n\nexports.Promise = Promise;\n","/**\n * Validate that the object only contains known option names\n * - Throws an error when unknown options are detected\n * - Throws an error when some of the allowed options are attached\n * @param {Object | undefined} options\n * @param {string[]} allowedOptionNames\n * @param {string} objectName\n * @retrun {Object} Returns the original options\n */\nexports.validateOptions = function validateOptions(options, allowedOptionNames, objectName) {\n if (!options) {\n return\n }\n\n var optionNames = options ? Object.keys(options) : []\n\n // check for unknown properties\n var unknownOptionName = optionNames.find(optionName => !allowedOptionNames.includes(optionName))\n if (unknownOptionName) {\n throw new Error('Object \"' + objectName + '\" contains an unknown option \"' + unknownOptionName + '\"')\n }\n\n // check for inherited properties which are not present on the object itself\n var illegalOptionName = allowedOptionNames.find(allowedOptionName => {\n return Object.prototype[allowedOptionName] && !optionNames.includes(allowedOptionName)\n })\n if (illegalOptionName) {\n throw new Error('Object \"' + objectName + '\" contains an inherited option \"' + illegalOptionName + '\" which is ' +\n 'not defined in the object itself but in its prototype. Only plain objects are allowed. ' +\n 'Please remove the option from the prototype or override it with a value \"undefined\".')\n }\n\n return options\n}\n\n// source: https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker\nexports.workerOptsNames = [\n 'credentials', 'name', 'type' ]\n\n// source: https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options\nexports.forkOptsNames = [\n 'cwd', 'detached', 'env', 'execPath', 'execArgv', 'gid', 'serialization',\n 'signal', 'killSignal', 'silent', 'stdio', 'uid', 'windowsVerbatimArguments',\n 'timeout'\n]\n\n// source: https://nodejs.org/api/worker_threads.html#new-workerfilename-options\nexports.workerThreadOptsNames = [\n 'argv', 'env', 'eval', 'execArgv', 'stdin', 'stdout', 'stderr', 'workerData',\n 'trackUnmanagedFds', 'transferList', 'resourceLimits', 'name'\n]\n","'use strict';\n\nvar {Promise} = require('./Promise');\nvar environment = require('./environment');\nconst {validateOptions, forkOptsNames, workerThreadOptsNames, workerOptsNames} = require(\"./validateOptions\");\n\n/**\n * Special message sent by parent which causes a child process worker to terminate itself.\n * Not a \"message object\"; this string is the entire message.\n */\nvar TERMINATE_METHOD_ID = '__workerpool-terminate__';\n\nfunction ensureWorkerThreads() {\n var WorkerThreads = tryRequireWorkerThreads()\n if (!WorkerThreads) {\n throw new Error('WorkerPool: workerType = \\'thread\\' is not supported, Node >= 11.7.0 required')\n }\n\n return WorkerThreads;\n}\n\n// check whether Worker is supported by the browser\nfunction ensureWebWorker() {\n // Workaround for a bug in PhantomJS (Or QtWebkit): https://github.com/ariya/phantomjs/issues/14534\n if (typeof Worker !== 'function' && (typeof Worker !== 'object' || typeof Worker.prototype.constructor !== 'function')) {\n throw new Error('WorkerPool: Web Workers not supported');\n }\n}\n\nfunction tryRequireWorkerThreads() {\n try {\n return require('worker_threads');\n } catch(error) {\n if (typeof error === 'object' && error !== null && error.code === 'MODULE_NOT_FOUND') {\n // no worker_threads available (old version of node.js)\n return null;\n } else {\n throw error;\n }\n }\n}\n\n// get the default worker script\nfunction getDefaultWorker() {\n if (environment.platform === 'browser') {\n // test whether the browser supports all features that we need\n if (typeof Blob === 'undefined') {\n throw new Error('Blob not supported by the browser');\n }\n if (!window.URL || typeof window.URL.createObjectURL !== 'function') {\n throw new Error('URL.createObjectURL not supported by the browser');\n }\n\n // use embedded worker.js\n var blob = new Blob([require('./generated/embeddedWorker')], {type: 'text/javascript'});\n return window.URL.createObjectURL(blob);\n }\n else {\n // use external worker.js in current directory\n return __dirname + '/worker.js';\n }\n}\n\nfunction setupWorker(script, options) {\n if (options.workerType === 'web') { // browser only\n ensureWebWorker();\n return setupBrowserWorker(script, options.workerOpts, Worker);\n } else if (options.workerType === 'thread') { // node.js only\n WorkerThreads = ensureWorkerThreads();\n return setupWorkerThreadWorker(script, WorkerThreads, options);\n } else if (options.workerType === 'process' || !options.workerType) { // node.js only\n return setupProcessWorker(script, resolveForkOptions(options), require('child_process'));\n } else { // options.workerType === 'auto' or undefined\n if (environment.platform === 'browser') {\n ensureWebWorker();\n return setupBrowserWorker(script, options.workerOpts, Worker);\n }\n else { // environment.platform === 'node'\n var WorkerThreads = tryRequireWorkerThreads();\n if (WorkerThreads) {\n return setupWorkerThreadWorker(script, WorkerThreads, options);\n } else {\n return setupProcessWorker(script, resolveForkOptions(options), require('child_process'));\n }\n }\n }\n}\n\nfunction setupBrowserWorker(script, workerOpts, Worker) {\n // validate the options right before creating the worker (not when creating the pool)\n validateOptions(workerOpts, workerOptsNames, 'workerOpts')\n\n // create the web worker\n var worker = new Worker(script, workerOpts);\n\n worker.isBrowserWorker = true;\n // add node.js API to the web worker\n worker.on = function (event, callback) {\n this.addEventListener(event, function (message) {\n callback(message.data);\n });\n };\n worker.send = function (message, transfer) {\n this.postMessage(message, transfer);\n };\n return worker;\n}\n\nfunction setupWorkerThreadWorker(script, WorkerThreads, options) {\n // validate the options right before creating the worker thread (not when creating the pool)\n validateOptions(options?.workerThreadOpts, workerThreadOptsNames, 'workerThreadOpts')\n\n var worker = new WorkerThreads.Worker(script, {\n stdout: options?.emitStdStreams ?? false, // pipe worker.STDOUT to process.STDOUT if not requested\n stderr: options?.emitStdStreams ?? false, // pipe worker.STDERR to process.STDERR if not requested\n ...options?.workerThreadOpts\n });\n worker.isWorkerThread = true;\n worker.send = function(message, transfer) {\n this.postMessage(message, transfer);\n };\n\n worker.kill = function() {\n this.terminate();\n return true;\n };\n\n worker.disconnect = function() {\n this.terminate();\n };\n\n if (options?.emitStdStreams) {\n worker.stdout.on('data', (data) => worker.emit(\"stdout\", data))\n worker.stderr.on('data', (data) => worker.emit(\"stderr\", data))\n }\n\n return worker;\n}\n\nfunction setupProcessWorker(script, options, child_process) {\n // validate the options right before creating the child process (not when creating the pool)\n validateOptions(options.forkOpts, forkOptsNames, 'forkOpts')\n\n // no WorkerThreads, fallback to sub-process based workers\n var worker = child_process.fork(\n script,\n options.forkArgs,\n options.forkOpts\n );\n\n // ignore transfer argument since it is not supported by process\n var send = worker.send;\n worker.send = function (message) {\n return send.call(worker, message);\n };\n\n if (options.emitStdStreams) {\n worker.stdout.on('data', (data) => worker.emit(\"stdout\", data))\n worker.stderr.on('data', (data) => worker.emit(\"stderr\", data))\n }\n\n worker.isChildProcess = true;\n return worker;\n}\n\n// add debug flags to child processes if the node inspector is active\nfunction resolveForkOptions(opts) {\n opts = opts || {};\n\n var processExecArgv = process.execArgv.join(' ');\n var inspectorActive = processExecArgv.indexOf('--inspect') !== -1;\n var debugBrk = processExecArgv.indexOf('--debug-brk') !== -1;\n\n var execArgv = [];\n if (inspectorActive) {\n execArgv.push('--inspect=' + opts.debugPort);\n\n if (debugBrk) {\n execArgv.push('--debug-brk');\n }\n }\n\n process.execArgv.forEach(function(arg) {\n if (arg.indexOf('--max-old-space-size') > -1) {\n execArgv.push(arg)\n }\n })\n\n return Object.assign({}, opts, {\n forkArgs: opts.forkArgs,\n forkOpts: Object.assign({}, opts.forkOpts, {\n execArgv: (opts.forkOpts && opts.forkOpts.execArgv || [])\n .concat(execArgv),\n stdio: opts.emitStdStreams ? \"pipe\": undefined\n })\n });\n}\n\n/**\n * Converts a serialized error to Error\n * @param {Object} obj Error that has been serialized and parsed to object\n * @return {Error} The equivalent Error.\n */\nfunction objectToError (obj) {\n var temp = new Error('')\n var props = Object.keys(obj)\n\n for (var i = 0; i < props.length; i++) {\n temp[props[i]] = obj[props[i]]\n }\n\n return temp\n}\n\nfunction handleEmittedStdPayload(handler, payload) {\n // TODO: refactor if parallel task execution gets added\n if (Object.keys(handler.processing).length !== 1) {\n return;\n }\n var task = Object.values(handler.processing)[0]\n if (task.options && typeof task.options.on === 'function') {\n task.options.on(payload);\n }\n}\n\n/**\n * A WorkerHandler controls a single worker. This worker can be a child process\n * on node.js or a WebWorker in a browser environment.\n * @param {String} [script] If no script is provided, a default worker with a\n * function run will be created.\n * @param {import('./types.js').WorkerPoolOptions} [_options] See docs\n * @constructor\n */\nfunction WorkerHandler(script, _options) {\n var me = this;\n var options = _options || {};\n\n this.script = script || getDefaultWorker();\n this.worker = setupWorker(this.script, options);\n this.debugPort = options.debugPort;\n this.forkOpts = options.forkOpts;\n this.forkArgs = options.forkArgs;\n this.workerOpts = options.workerOpts;\n this.workerThreadOpts = options.workerThreadOpts\n this.workerTerminateTimeout = options.workerTerminateTimeout;\n\n // The ready message is only sent if the worker.add method is called (And the default script is not used)\n if (!script) {\n this.worker.ready = true;\n }\n\n // queue for requests that are received before the worker is ready\n this.requestQueue = [];\n\n this.worker.on(\"stdout\", function (data) {\n handleEmittedStdPayload(me, {\"stdout\": data.toString()})\n })\n this.worker.on(\"stderr\", function (data) {\n handleEmittedStdPayload(me, {\"stderr\": data.toString()})\n })\n\n this.worker.on('message', function (response) {\n if (me.terminated) {\n return;\n }\n if (typeof response === 'string' && response === 'ready') {\n me.worker.ready = true;\n dispatchQueuedRequests();\n } else {\n // find the task from the processing queue, and run the tasks callback\n var id = response.id;\n var task = me.processing[id];\n if (task !== undefined) {\n if (response.isEvent) {\n if (task.options && typeof task.options.on === 'function') {\n task.options.on(response.payload);\n }\n } else {\n // remove the task from the queue\n delete me.processing[id];\n\n // test if we need to terminate\n if (me.terminating === true) {\n // complete worker termination if all tasks are finished\n me.terminate();\n }\n\n // resolve the task's promise\n if (response.error) {\n task.resolver.reject(objectToError(response.error));\n }\n else {\n task.resolver.resolve(response.result);\n }\n }\n }\n }\n });\n\n // reject all running tasks on worker error\n function onError(error) {\n me.terminated = true;\n\n for (var id in me.processing) {\n if (me.processing[id] !== undefined) {\n me.processing[id].resolver.reject(error);\n }\n }\n me.processing = Object.create(null);\n }\n\n // send all queued requests to worker\n function dispatchQueuedRequests()\n {\n for(const request of me.requestQueue.splice(0)) {\n me.worker.send(request.message, request.transfer);\n }\n }\n\n var worker = this.worker;\n // listen for worker messages error and exit\n this.worker.on('error', onError);\n this.worker.on('exit', function (exitCode, signalCode) {\n var message = 'Workerpool Worker terminated Unexpectedly\\n';\n\n message += ' exitCode: `' + exitCode + '`\\n';\n message += ' signalCode: `' + signalCode + '`\\n';\n\n message += ' workerpool.script: `' + me.script + '`\\n';\n message += ' spawnArgs: `' + worker.spawnargs + '`\\n';\n message += ' spawnfile: `' + worker.spawnfile + '`\\n'\n\n message += ' stdout: `' + worker.stdout + '`\\n'\n message += ' stderr: `' + worker.stderr + '`\\n'\n\n onError(new Error(message));\n });\n\n this.processing = Object.create(null); // queue with tasks currently in progress\n\n this.terminating = false;\n this.terminated = false;\n this.cleaning = false;\n this.terminationHandler = null;\n this.lastId = 0;\n}\n\n/**\n * Get a list with methods available on the worker.\n * @return {Promise.<String[], Error>} methods\n */\nWorkerHandler.prototype.methods = function () {\n return this.exec('methods');\n};\n\n/**\n * Execute a method with given parameters on the worker\n * @param {String} method\n * @param {Array} [params]\n * @param {{resolve: Function, reject: Function}} [resolver]\n * @param {import('./types.js').ExecOptions} [options]\n * @return {Promise.<*, Error>} result\n */\nWorkerHandler.prototype.exec = function(method, params, resolver, options) {\n if (!resolver) {\n resolver = Promise.defer();\n }\n\n // generate a unique id for the task\n var id = ++this.lastId;\n\n // register a new task as being in progress\n this.processing[id] = {\n id: id,\n resolver: resolver,\n options: options\n };\n\n // build a JSON-RPC request\n var request = {\n message: {\n id: id,\n method: method,\n params: params\n },\n transfer: options && options.transfer\n };\n\n if (this.terminated) {\n resolver.reject(new Error('Worker is terminated'));\n } else if (this.worker.ready) {\n // send the request to the worker\n this.worker.send(request.message, request.transfer);\n } else {\n this.requestQueue.push(request);\n }\n\n // on cancellation, force the worker to terminate\n var me = this;\n return resolver.promise.catch(function (error) {\n if (error instanceof Promise.CancellationError || error instanceof Promise.TimeoutError) {\n // remove this task from the queue. It is already rejected (hence this\n // catch event), and else it will be rejected again when terminating\n delete me.processing[id];\n\n // terminate worker\n return me.terminateAndNotify(true)\n .then(function() {\n throw error;\n }, function(err) {\n throw err;\n });\n } else {\n throw error;\n }\n })\n};\n\n/**\n * Test whether the worker is processing any tasks or cleaning up before termination.\n * @return {boolean} Returns true if the worker is busy\n */\nWorkerHandler.prototype.busy = function () {\n return this.cleaning || Object.keys(this.processing).length > 0;\n};\n\n/**\n * Terminate the worker.\n * @param {boolean} [force=false] If false (default), the worker is terminated\n * after finishing all tasks currently in\n * progress. If true, the worker will be\n * terminated immediately.\n * @param {function} [callback=null] If provided, will be called when process terminates.\n */\nWorkerHandler.prototype.terminate = function (force, callback) {\n var me = this;\n if (force) {\n // cancel all tasks in progress\n for (var id in this.processing) {\n if (this.processing[id] !== undefined) {\n this.processing[id].resolver.reject(new Error('Worker terminated'));\n }\n }\n this.processing = Object.create(null);\n }\n\n if (typeof callback === 'function') {\n this.terminationHandler = callback;\n }\n if (!this.busy()) {\n // all tasks are finished. kill the worker\n var cleanup = function(err) {\n me.terminated = true;\n me.cleaning = false;\n if (me.worker != null && me.worker.removeAllListeners) {\n // removeAllListeners is only available for child_process\n me.worker.removeAllListeners('message');\n }\n me.worker = null;\n me.terminating = false;\n if (me.terminationHandler) {\n me.terminationHandler(err, me);\n } else if (err) {\n throw err;\n }\n }\n\n if (this.worker) {\n if (typeof this.worker.kill === 'function') {\n if (this.worker.killed) {\n cleanup(new Error('worker already killed!'));\n return;\n }\n\n // child process and worker threads\n var cleanExitTimeout = setTimeout(function() {\n if (me.worker) {\n me.worker.kill();\n }\n }, this.workerTerminateTimeout);\n\n this.worker.once('exit', function() {\n clearTimeout(cleanExitTimeout);\n if (me.worker) {\n me.worker.killed = true;\n }\n cleanup();\n });\n\n if (this.worker.ready) {\n this.worker.send(TERMINATE_METHOD_ID);\n } else {\n this.requestQueue.push({ message: TERMINATE_METHOD_ID });\n }\n\n // mark that the worker is cleaning up resources\n // to prevent new tasks from being executed\n this.cleaning = true;\n return;\n }\n else if (typeof this.worker.terminate === 'function') {\n this.worker.terminate(); // web worker\n this.worker.killed = true;\n }\n else {\n throw new Error('Failed to terminate worker');\n }\n }\n cleanup();\n }\n else {\n // we can't terminate immediately, there are still tasks being executed\n this.terminating = true;\n }\n};\n\n/**\n * Terminate the worker, returning a Promise that resolves when the termination has been done.\n * @param {boolean} [force=false] If false (default), the worker is terminated\n * after finishing all tasks currently in\n * progress. If true, the worker will be\n * terminated immediately.\n * @param {number} [timeout] If provided and non-zero, worker termination promise will be rejected\n * after timeout if worker process has not been terminated.\n * @return {Promise.<WorkerHandler, Error>}\n */\nWorkerHandler.prototype.terminateAndNotify = function (force, timeout) {\n var resolver = Promise.defer();\n if (timeout) {\n resolver.promise.timeout(timeout);\n }\n this.terminate(force, function(err, worker) {\n if (err) {\n resolver.reject(err);\n } else {\n resolver.resolve(worker);\n }\n });\n return resolver.promise;\n};\n\nmodule.exports = WorkerHandler;\nmodule.exports._tryRequireWorkerThreads = tryRequireWorkerThreads;\nmodule.exports._setupProcessWorker = setupProcessWorker;\nmodule.exports._setupBrowserWorker = setupBrowserWorker;\nmodule.exports._setupWorkerThreadWorker = setupWorkerThreadWorker;\nmodule.exports.ensureWorkerThreads = ensureWorkerThreads;\n","/**\n * embeddedWorker.js contains an embedded version of worker.js.\n * This file is automatically generated,\n * changes made in this file will be overwritten.\n */\nmodule.exports = \"!function(e,n){\\\"object\\\"==typeof exports&&\\\"undefined\\\"!=typeof module?module.exports=n():\\\"function\\\"==typeof define&&define.amd?define(n):(e=\\\"undefined\\\"!=typeof globalThis?globalThis:e||self).worker=n()}(this,(function(){\\\"use strict\\\";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,\\\"default\\\")?e.default:e}var n={};var t=function(e,n){this.message=e,this.transfer=n};return function(e){var n=t,r={exit:function(){}};if(\\\"undefined\\\"!=typeof self&&\\\"function\\\"==typeof postMessage&&\\\"function\\\"==typeof addEventListener)r.on=function(e,n){addEventListener(e,(function(e){n(e.data)}))},r.send=function(e){postMessage(e)};else{if(\\\"undefined\\\"==typeof process)throw new Error(\\\"Script must be executed as a worker\\\");var o;try{o=require(\\\"worker_threads\\\")}catch(e){if(\\\"object\\\"!=typeof e||null===e||\\\"MODULE_NOT_FOUND\\\"!==e.code)throw e}if(o&&null!==o.parentPort){var i=o.parentPort;r.send=i.postMessage.bind(i),r.on=i.on.bind(i),r.exit=process.exit.bind(process)}else r.on=process.on.bind(process),r.send=function(e){process.send(e)},r.on(\\\"disconnect\\\",(function(){process.exit(1)})),r.exit=process.exit.bind(process)}function s(e){return Object.getOwnPropertyNames(e).reduce((function(n,t){return Object.defineProperty(n,t,{value:e[t],enumerable:!0})}),{})}function d(e){return e&&\\\"function\\\"==typeof e.then&&\\\"function\\\"==typeof e.catch}r.methods={},r.methods.run=function(e,n){var t=new Function(\\\"return (\\\"+e+\\\").apply(null, arguments);\\\");return t.apply(t,n)},r.methods.methods=function(){return Object.keys(r.methods)},r.terminationHandler=void 0,r.cleanupAndExit=function(e){var n=function(){r.exit(e)};if(!r.terminationHandler)return n();var t=r.terminationHandler(e);d(t)?t.then(n,n):n()};var u=null;r.on(\\\"message\\\",(function(e){if(\\\"__workerpool-terminate__\\\"===e)return r.cleanupAndExit(0);try{var t=r.methods[e.method];if(!t)throw new Error('Unknown method \\\"'+e.method+'\\\"');u=e.id;var o=t.apply(t,e.params);d(o)?o.then((function(t){t instanceof n?r.send({id:e.id,result:t.message,error:null},t.transfer):r.send({id:e.id,result:t,error:null}),u=null})).catch((function(n){r.send({id:e.id,result:null,error:s(n)}),u=null})):(o instanceof n?r.send({id:e.id,result:o.message,error:null},o.transfer):r.send({id:e.id,result:o,error:null}),u=null)}catch(n){r.send({id:e.id,result:null,error:s(n)})}})),r.register=function(e,n){if(e)for(var t in e)e.hasOwnProperty(t)&&(r.methods[t]=e[t]);n&&(r.terminationHandler=n.onTerminate),r.send(\\\"ready\\\")},r.emit=function(e){if(u){if(e instanceof n)return void r.send({id:u,isEvent:!0,payload:e.message},e.transfer);r.send({id:u,isEvent:!0,payload:e})}},e.add=r.register,e.emit=r.emit}(n),e(n)}));\\n//# sourceMappingURL=worker.min.js.map\\n\";\n","var {Promise} = require('./Promise');\nvar WorkerHandler = require('./WorkerHandler');\nvar environment = require('./environment');\nvar DebugPortAllocator = require('./debug-port-allocator');\nvar DEBUG_PORT_ALLOCATOR = new DebugPortAllocator();\n/**\n * A pool to manage workers, which can be created using the function workerpool.pool.\n *\n * @param {String} [script] Optional worker script\n * @param {import('./types.js').WorkerPoolOptions} [options] See docs\n * @constructor\n */\nfunction Pool(script, options) {\n if (typeof script === 'string') {\n /** @readonly */\n this.script = script || null;\n }\n else {\n this.script = null;\n options = script;\n }\n\n /** @private */\n this.workers = []; // queue with all workers\n /** @private */\n this.tasks = []; // queue with tasks awaiting execution\n\n options = options || {};\n\n /** @readonly */\n this.forkArgs = Object.freeze(options.forkArgs || []);\n /** @readonly */\n this.forkOpts = Object.freeze(options.forkOpts || {});\n /** @readonly */\n this.workerOpts = Object.freeze(options.workerOpts || {});\n /** @readonly */\n this.workerThreadOpts = Object.freeze(options.workerThreadOpts || {})\n /** @private */\n this.debugPortStart = (options.debugPortStart || 43210);\n /** @readonly @deprecated */\n this.nodeWorker = options.nodeWorker;\n /** @readonly\n * @type {'auto' | 'web' | 'process' | 'thread'}\n */\n this.workerType = options.workerType || options.nodeWorker || 'auto'\n /** @readonly */\n this.maxQueueSize = options.maxQueueSize || Infinity;\n /** @readonly */\n this.workerTerminateTimeout = options.workerTerminateTimeout || 1000;\n\n /** @readonly */\n this.onCreateWorker = options.onCreateWorker || (() => null);\n /** @readonly */\n this.onTerminateWorker = options.onTerminateWorker || (() => null);\n\n /** @readonly */\n this.emitStdStreams = options.emitStdStreams || false\n\n // configuration\n if (options && 'maxWorkers' in options) {\n validateMaxWorkers(options.maxWorkers);\n /** @readonly */\n this.maxWorkers = options.maxWorkers;\n }\n else {\n this.maxWorkers = Math.max((environment.cpus || 4) - 1, 1);\n }\n\n if (options && 'minWorkers' in options) {\n if(options.minWorkers === 'max') {\n /** @readonly */\n this.minWorkers = this.maxWorkers;\n } else {\n validateMinWorkers(options.minWorkers);\n this.minWorkers = options.minWorkers;\n this.maxWorkers = Math.max(this.minWorkers, this.maxWorkers); // in case minWorkers is higher than maxWorkers\n }\n this._ensureMinWorkers();\n }\n\n /** @private */\n this._boundNext = this._next.bind(this);\n\n\n if (this.workerType === 'thread') {\n WorkerHandler.ensureWorkerThreads();\n }\n}\n\n\n/**\n * Execute a function on a worker.\n *\n * Example usage:\n *\n * var pool = new Pool()\n *\n * // call a function available on the worker\n * pool.exec('fibonacci', [6])\n *\n * // offload a function\n * function add(a, b) {\n * return a + b\n * };\n * pool.exec(add, [2, 4])\n * .then(function (result) {\n * console.log(result); // outputs 6\n * })\n * .catch(function(error) {\n * console.log(error);\n * });\n * @template { (...args: any[]) => any } T\n * @param {String | T} method Function name or function.\n * If `method` is a string, the corresponding\n * method on the worker will be executed\n * If `method` is a Function, the function\n * will be stringified and executed via the\n * workers built-in function `run(fn, args)`.\n * @param {Parameters<T> | null} [params] Function arguments applied when calling the function\n * @param {import('./types.js').ExecOptions} [options] Options\n * @return {Promise<ReturnType<T>>}\n */\nPool.prototype.exec = function (method, params, options) {\n // validate type of arguments\n if (params && !Array.isArray(params)) {\n throw new TypeError('Array expected as argument \"params\"');\n }\n\n if (typeof method === 'string') {\n var resolver = Promise.defer();\n\n if (this.tasks.length >= this.maxQueueSize) {\n throw new Error('Max queue size of ' + this.maxQueueSize + ' reached');\n }\n\n // add a new task to the queue\n var tasks = this.tasks;\n var task = {\n method: method,\n params: params,\n resolver: resolver,\n timeout: null,\n options: options\n };\n tasks.push(task);\n\n // replace the timeout method of the Promise with our own,\n // which starts the timer as soon as the task is actually started\n var originalTimeout = resolver.promise.timeout;\n resolver.promise.timeout = function timeout (delay) {\n if (tasks.indexOf(task) !== -1) {\n // task is still queued -> start the timer later on\n task.timeout = delay;\n return resolver.promise;\n }\n else {\n // task is already being executed -> start timer immediately\n return originalTimeout.call(resolver.promise, delay);\n }\n };\n\n // trigger task execution\n this._next();\n\n return resolver.promise;\n }\n else if (typeof method === 'function') {\n // send stringified function and function arguments to worker\n return this.exec('run', [String(method), params], options);\n }\n else {\n throw new TypeError('Function or string expected as argument \"method\"');\n }\n};\n\n/**\n * Create a proxy for current worker. Returns an object containing all\n * methods available on the worker. All methods return promises resolving the methods result.\n * @template { { [k: string]: (...args: any[]) => any } } T\n * @return {Promise<import('./types.js').Proxy<T>, Error>} Returns a promise which resolves with a proxy object\n */\nPool.prototype.proxy = function () {\n if (arguments.length > 0) {\n throw new Error('No arguments expected');\n }\n\n var pool = this;\n return this.exec('methods')\n .then(function (methods) {\n var proxy = {};\n\n methods.forEach(function (method) {\n proxy[method] = function () {\n return pool.exec(method, Array.prototype.slice.call(arguments));\n }\n });\n\n return proxy;\n });\n};\n\n/**\n * Creates new array with the results of calling a provided callback function\n * on every element in this array.\n * @param {Array} array\n * @param {function} callback Function taking two arguments:\n * `callback(currentValue, index)`\n * @return {Promise.<Array>} Returns a promise which resolves with an Array\n * containing the results of the callback function\n * executed for each of the array elements.\n */\n/* TODO: implement map\nPool.prototype.map = function (array, callback) {\n};\n*/\n\n/**\n * Grab the first task from the queue, find a free worker, and assign the\n * worker to the task.\n * @private\n */\nPool.prototype._next = function () {\n if (this.tasks.length > 0) {\n // there are tasks in the queue\n\n // find an available worker\n var worker = this._getWorker();\n if (worker) {\n // get the first task from the queue\n var me = this;\n var task = this.tasks.shift();\n\n // check if the task is still pending (and not cancelled -> promise rejected)\n if (task.resolver.promise.pending) {\n // send the request to the worker\n var promise = worker.exec(task.method, task.params, task.resolver, task.options)\n .then(me._boundNext)\n .catch(function () {\n // if the worker crashed and terminated, remove it from the pool\n if (worker.terminated) {\n return me._removeWorker(worker);\n }\n }).then(function() {\n me._next(); // trigger next task in the queue\n });\n\n // start queued timer now\n if (typeof task.timeout === 'number') {\n promise.timeout(task.timeout);\n }\n } else {\n // The task taken was already complete (either rejected or resolved), so just trigger next task in the queue\n me._next();\n }\n }\n }\n};\n\n/**\n * Get an available worker. If no worker is available and the maximum number\n * of workers isn't yet reached, a new worker will be created and returned.\n * If no worker is available and the maximum number of workers is reached,\n * null will be returned.\n *\n * @return {WorkerHandler | null} worker\n * @private\n */\nPool.prototype._getWorker = function() {\n // find a non-busy worker\n var workers = this.workers;\n for (var i = 0; i < workers.length; i++) {\n var worker = workers[i];\n if (worker.busy() === false) {\n return worker;\n }\n }\n\n if (workers.length < this.maxWorkers) {\n // create a new worker\n worker = this._createWorkerHandler();\n workers.push(worker);\n return worker;\n }\n\n return null;\n};\n\n/**\n * Remove a worker from the pool.\n * Attempts to terminate worker if not already terminated, and ensures the minimum\n * pool size is met.\n * @param {WorkerHandler} worker\n * @return {Promise<WorkerHandler>}\n * @private\n */\nPool.prototype._removeWorker = function(worker) {\n var me = this;\n\n DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);\n // _removeWorker will call this, but we need it to be removed synchronously\n this._removeWorkerFromList(worker);\n // If minWorkers set, spin up new workers to replace the crashed ones\n this._ensureMinWorkers();\n // terminate the worker (if not already terminated)\n return new Promise(function(resolve, reject) {\n worker.terminate(false, function(err) {\n me.onTerminateWorker({\n forkArgs: worker.forkArgs,\n forkOpts: worker.forkOpts,\n workerThreadOpts: worker.workerThreadOpts,\n script: worker.script\n });\n if (err) {\n reject(err);\n } else {\n resolve(worker);\n }\n });\n });\n};\n\n/**\n * Remove a worker from the pool list.\n * @param {WorkerHandler} worker\n * @private\n */\nPool.prototype._removeWorkerFromList = function(worker) {\n // remove from the list with workers\n var index = this.workers.indexOf(worker);\n if (index !== -1) {\n this.workers.splice(index, 1);\n }\n};\n\n/**\n * Close all active workers. Tasks currently being executed will be finished first.\n * @param {boolean} [force=false] If false (default), the workers are terminated\n * after finishing all tasks currently in\n * progress. If true, the workers will be\n * terminated immediately.\n * @param {number} [timeout] If provided and non-zero, worker termination promise will be rejected\n * after timeout if worker process has not been terminated.\n * @return {Promise.<void, Error>}\n */\nPool.prototype.terminate = function (force, timeout) {\n var me = this;\n\n // cancel any pending tasks\n this.tasks.forEach(function (task) {\n task.resolver.reject(new Error('Pool terminated'));\n });\n this.tasks.length = 0;\n\n var f = function (worker) {\n DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);\n this._removeWorkerFromList(worker);\n };\n var removeWorker = f.bind(this);\n\n var promises = [];\n var workers = this.workers.slice();\n workers.forEach(function (worker) {\n var termPromise = worker.terminateAndNotify(force, timeout)\n .then(removeWorker)\n .always(function() {\n me.onTerminateWorker({\n forkArgs: worker.forkArgs,\n forkOpts: worker.forkOpts,\n workerThreadOpts: worker.workerThreadOpts,\n script: worker.script\n });\n });\n promises.push(termPromise);\n });\n return Promise.all(promises);\n};\n\n/**\n * Retrieve statistics on tasks and workers.\n * @return {{totalWorkers: number, busyWorkers: number, idleWorkers: number, pendingTasks: number, activeTasks: number}} Returns an object with statistics\n */\nPool.prototype.stats = function () {\n var totalWorkers = this.workers.length;\n var busyWorkers = this.workers.filter(function (worker) {\n return worker.busy();\n }).length;\n\n return {\n totalWorkers: totalWorkers,\n busyWorkers: busyWorkers,\n idleWorkers: totalWorkers - busyWorkers,\n\n pendingTasks: this.tasks.length,\n activeTasks: busyWorkers\n };\n};\n\n/**\n * Ensures that a minimum of minWorkers is up and running\n * @private\n */\nPool.prototype._ensureMinWorkers = function() {\n if (this.minWorkers) {\n for(var i = this.workers.length; i < this.minWorkers; i++) {\n this.workers.push(this._createWorkerHandler());\n }\n }\n};\n\n/**\n * Helper function to create a new WorkerHandler and pass all options.\n * @return {WorkerHandler}\n * @private\n */\nPool.prototype._createWorkerHandler = function () {\n const overriddenParams = this.onCreateWorker({\n forkArgs: this.forkArgs,\n forkOpts: this.forkOpts,\n workerOpts: this.workerOpts,\n workerThreadOpts: this.workerThreadOpts,\n script: this.script\n }) || {};\n\n return new WorkerHandler(overriddenParams.script || this.script, {\n forkArgs: overriddenParams.forkArgs || this.forkArgs,\n forkOpts: overriddenParams.forkOpts || this.forkOpts,\n workerOpts: overriddenParams.workerOpts || this.workerOpts,\n workerThreadOpts: overriddenParams.workerThreadOpts || this.workerThreadOpts,\n debugPort: DEBUG_PORT_ALLOCATOR.nextAvailableStartingAt(this.debugPortStart),\n workerType: this.workerType,\n workerTerminateTimeout: this.workerTerminateTimeout,\n emitStdStreams: this.emitStdStreams,\n });\n}\n\n/**\n * Ensure that the maxWorkers option is an integer >= 1\n * @param {*} maxWorkers\n * @returns {boolean} returns true maxWorkers has a valid value\n */\nfunction validateMaxWorkers(maxWorkers) {\n if (!isNumber(maxWorkers) || !isInteger(maxWorkers) || maxWorkers < 1) {\n throw new TypeError('Option maxWorkers must be an integer number >= 1');\n }\n}\n\n/**\n * Ensure that the minWorkers option is an integer >= 0\n * @param {*} minWorkers\n * @returns {boolean} returns true when minWorkers has a valid value\n */\nfunction validateMinWorkers(minWorkers) {\n if (!isNumber(minWorkers) || !isInteger(minWorkers) || minWorkers < 0) {\n throw new TypeError('Option minWorkers must be an integer number >= 0');\n }\n}\n\n/**\n * Test whether a variable is a number\n * @param {*} value\n * @returns {boolean} returns true when value is a number\n */\nfunction isNumber(value) {\n return typeof value === 'number';\n}\n\n/**\n * Test whether a number is an integer\n * @param {number} value\n * @returns {boolean} Returns true if value is an integer\n */\nfunction isInteger(value) {\n return Math.round(value) == value;\n}\n\nmodule.exports = Pool;\n","'use strict';\n\nvar MAX_PORTS = 65535;\nmodule.exports = DebugPortAllocator;\nfunction DebugPortAllocator() {\n this.ports = Object.create(null);\n this.length = 0;\n}\n\nDebugPortAllocator.prototype.nextAvailableStartingAt = function(starting) {\n while (this.ports[starting] === true) {\n starting++;\n }\n\n if (starting >= MAX_PORTS) {\n throw new Error('WorkerPool debug port limit reached: ' + starting + '>= ' + MAX_PORTS );\n }\n\n this.ports[starting] = true;\n this.length++;\n return starting;\n};\n\nDebugPortAllocator.prototype.releasePort = function(port) {\n delete this.ports[port];\n this.length--;\n};\n\n","/**\n * The helper class for transferring data from the worker to the main thread.\n *\n * @param {Object} message The object to deliver to the main thread.\n * @param {Object[]} transfer An array of transferable Objects to transfer ownership of.\n */\nfunction Transfer(message, transfer) {\n this.message = message;\n this.transfer = transfer;\n}\n\nmodule.exports = Transfer;\n","/**\n * worker must be started as a child process or a web worker.\n * It listens for RPC messages from the parent process.\n */\nvar Transfer = require('./transfer');\n\n/**\n * Special message sent by parent which causes the worker to terminate itself.\n * Not a \"message object\"; this string is the entire message.\n */\nvar TERMINATE_METHOD_ID = '__workerpool-terminate__';\n\n// var nodeOSPlatform = require('./environment').nodeOSPlatform;\n\n// create a worker API for sending and receiving messages which works both on\n// node.js and in the browser\nvar worker = {\n exit: function() {}\n};\nif (typeof self !== 'undefined' && typeof postMessage === 'function' && typeof addEventListener === 'function') {\n // worker in the browser\n worker.on = function (event, callback) {\n addEventListener(event, function (message) {\n callback(message.data);\n })\n };\n worker.send = function (message) {\n postMessage(message);\n };\n}\nelse if (typeof process !== 'undefined') {\n // node.js\n\n var WorkerThreads;\n try {\n WorkerThreads = require('worker_threads');\n } catch(error) {\n if (typeof error === 'object' && error !== null && error.code === 'MODULE_NOT_FOUND') {\n // no worker_threads, fallback to sub-process based workers\n } else {\n throw error;\n }\n }\n\n if (WorkerThreads &&\n /* if there is a parentPort, we are in a WorkerThread */\n WorkerThreads.parentPort !== null) {\n var parentPort = WorkerThreads.parentPort;\n worker.send = parentPort.postMessage.bind(parentPort);\n worker.on = parentPort.on.bind(parentPort);\n worker.exit = process.exit.bind(process);\n } else {\n worker.on = process.on.bind(process);\n // ignore transfer argument since it is not supported by process\n worker.send = function (message) {\n process.send(message);\n };\n // register disconnect handler only for subprocess worker to exit when parent is killed unexpectedly\n worker.on('disconnect', function () {\n process.exit(1);\n });\n worker.exit = process.exit.bind(process);\n }\n}\nelse {\n throw new Error('Script must be executed as a worker');\n}\n\nfunction convertError(error) {\n return Object.getOwnPropertyNames(error).reduce(function(product, name) {\n return Object.defineProperty(product, name, {\n\tvalue: error[name],\n\tenumerable: true\n });\n }, {});\n}\n\n/**\n * Test whether a value is a Promise via duck typing.\n * @param {*} value\n * @returns {boolean} Returns true when given value is an object\n * having functions `then` and `catch`.\n */\nfunction isPromise(value) {\n return value && (typeof value.then === 'function') && (typeof value.catch === 'function');\n}\n\n// functions available externally\nworker.methods = {};\n\n/**\n * Execute a function with provided arguments\n * @param {String} fn Stringified function\n * @param {Array} [args] Function arguments\n * @returns {*}\n */\nworker.methods.run = function run(fn, args) {\n var f = new Function('return (' + fn + ').apply(null, arguments);');\n return f.apply(f, args);\n};\n\n/**\n * Get a list with methods available on this worker\n * @return {String[]} methods\n */\nworker.methods.methods = function methods() {\n return Object.keys(worker.methods);\n};\n\n/**\n * Custom handler for when the worker is terminated.\n */\nworker.terminationHandler = undefined;\n\n/**\n * Cleanup and exit the worker.\n * @param {Number} code \n * @returns \n */\nworker.cleanupAndExit = function(code) {\n var _exit = function() {\n worker.exit(code);\n }\n\n if(!worker.terminationHandler) {\n return _exit();\n }\n\n var result = worker.terminationHandler(code);\n if (isPromise(result)) {\n result.then(_exit, _exit);\n } else {\n _exit();\n }\n}\n\nvar currentRequestId = null;\n\nworker.on('message', function (request) {\n if (request === TERMINATE_METHOD_ID) {\n return worker.cleanupAndExit(0);\n }\n try {\n var method = worker.methods[request.method];\n\n if (method) {\n currentRequestId = request.id;\n \n // execute the function\n var result = method.apply(method, request.params);\n\n if (isPromise(result)) {\n // promise returned, resolve this and then return\n result\n .then(function (result) {\n if (result instanceof Transfer) {\n worker.send({\n id: request.id,\n result: result.message,\n error: null\n }, result.transfer);\n } else {\n worker.send({\n id: request.id,\n result: result,\n error: null\n });\n }\n currentRequestId = null;\n })\n .catch(function (err) {\n worker.send({\n id: request.id,\n result: null,\n error: convertError(err)\n });\n currentRequestId = null;\n });\n }\n else {\n // immediate result\n if (result instanceof Transfer) {\n worker.send({\n id: request.id,\n result: result.message,\n error: null\n }, result.transfer);\n } else {\n worker.send({\n id: request.id,\n result: result,\n error: null\n });\n }\n\n currentRequestId = null;\n }\n }\n else {\n throw new Error('Unknown method \"' + request.method + '\"');\n }\n }\n catch (err) {\n worker.send({\n id: request.id,\n result: null,\n error: convertError(err)\n });\n }\n});\n\n/**\n * Register methods to the worker\n * @param {Object} [methods]\n * @param {import('./types.js').WorkerRegisterOptions} [options]\n */\nworker.register = function (methods, options) {\n\n if (methods) {\n for (var name in methods) {\n if (methods.hasOwnProperty(name)) {\n worker.methods[name] = methods[name];\n }\n }\n }\n\n if (options) {\n worker.terminationHandler = options.onTerminate;\n }\n\n worker.send('ready');\n};\n\nworker.emit = function (payload) {\n if (currentRequestId) {\n if (payload instanceof Transfer) {\n worker.send({\n id: currentRequestId,\n isEvent: true,\n payload: payload.message\n }, payload.transfer);\n return;\n }\n\n worker.send({\n id: currentRequestId,\n isEvent: true,\n payload\n });\n }\n};\n\nif (typeof exports !== 'undefined') {\n exports.add = worker.register;\n exports.emit = worker.emit;\n}\n","const {platform, isMainThread, cpus} = require('./environment');\n\n/** @typedef {import(\"./Pool\")} Pool */\n/** @typedef {import(\"./types.js\").WorkerPoolOptions} WorkerPoolOptions */\n/** @typedef {import(\"./types.js\").WorkerRegisterOptions} WorkerRegisterOptions */\n\n/**\n * @template { { [k: string]: (...args: any[]) => any } } T\n * @typedef {import('./types.js').Proxy<T>} Proxy<T>\n */\n\n/**\n * @overload\n * Create a new worker pool\n * @param {WorkerPoolOptions} [script]\n * @returns {Pool} pool\n */\n/**\n * @overload\n * Create a new worker pool\n * @param {string} [script]\n * @param {WorkerPoolOptions} [options]\n * @returns {Pool} pool\n */\nfunction pool(script, options) {\n var Pool = require('./Pool');\n\n return new Pool(script, options);\n};\nexports.pool = pool;\n\n/**\n * Create a worker and optionally register a set of methods to the worker.\n * @param {{ [k: string]: (...args: any[]) => any }} [methods]\n * @param {WorkerRegisterOptions} [options]\n */\nfunction worker(methods, options) {\n var worker = require('./worker');\n worker.add(methods, options);\n};\nexports.worker = worker;\n\n/**\n * Sends an event to the parent worker pool.\n * @param {any} payload \n */\nfunction workerEmit(payload) {\n var worker = require('./worker');\n worker.emit(payload);\n};\nexports.workerEmit = workerEmit;\n\nconst {Promise} = require('./Promise');\nexports.Promise = Promise;\n\nexports.Transfer = require('./transfer');\n\nexports.platform = platform;\nexports.isMainThread = isMainThread;\nexports.cpus = cpus;\n"],"names":["isNode","nodeProcess","versions","node","module","exports","platform","process","worker_threads","require","isMainThread","connected","Window","cpus","self","navigator","hardwareConcurrency","length","Promise","handler","parent","me","this","SyntaxError","_onSuccess","_onFail","resolved","rejected","pending","_process","onSuccess","onFail","push","then","resolve","reject","s","_then","f","_resolve","result","forEach","fn","_reject","error","cancel","CancellationError","timeout","delay","timer","setTimeout","TimeoutError","always","clearTimeout","callback","res","message","stack","Error","prototype","all","promises","remaining","results","p","i","defer","resolver","promise","constructor","name","_Promise","validateOptions","options","allowedOptionNames","objectName","optionNames","Object","keys","unknownOptionName","find","optionName","includes","illegalOptionName","allowedOptionName","workerOptsNames","forkOptsNames","workerThreadOptsNames","require$$0","environment","require$$1","require$$2","TERMINATE_METHOD_ID","ensureWorkerThreads","WorkerThreads","tryRequireWorkerThreads","ensureWebWorker","Worker","code","setupBrowserWorker","script","workerOpts","worker","isBrowserWorker","on","event","addEventListener","data","send","transfer","postMessage","setupWorkerThreadWorker","workerThreadOpts","stdout","emitStdStreams","stderr","isWorkerThread","kill","terminate","disconnect","emit","setupProcessWorker","child_process","forkOpts","fork","forkArgs","call","isChildProcess","resolveForkOptions","opts","processExecArgv","execArgv","join","inspectorActive","indexOf","debugBrk","debugPort","arg","assign","concat","stdio","undefined","handleEmittedStdPayload","payload","processing","task","values","WorkerHandler","_options","onError","id","terminated","create","Blob","window","URL","createObjectURL","blob","embeddedWorker","type","__dirname","getDefaultWorker","workerType","setupWorker","workerTerminateTimeout","ready","requestQueue","toString","response","request","splice","dispatchQueuedRequests","isEvent","terminating","obj","temp","props","objectToError","exitCode","signalCode","spawnargs","spawnfile","cleaning","terminationHandler","lastId","methods","exec","method","params","catch","terminateAndNotify","err","busy","force","cleanup","removeAllListeners","killed","cleanExitTimeout","once","WorkerHandlerModule","_tryRequireWorkerThreads","_setupProcessWorker","_setupBrowserWorker","_setupWorkerThreadWorker","DEBUG_PORT_ALLOCATOR","DebugPortAllocator","ports","debugPortAllocator","nextAvailableStartingAt","starting","releasePort","port","require$$3","Pool","workers","tasks","freeze","debugPortStart","nodeWorker","maxQueueSize","Infinity","onCreateWorker","onTerminateWorker","maxWorkers","isNumber","isInteger","TypeError","validateMaxWorkers","Math","max","minWorkers","validateMinWorkers","_ensureMinWorkers","_boundNext","_next","bind","value","round","Array","isArray","originalTimeout","String","proxy","arguments","pool","slice","_getWorker","shift","_removeWorker","_createWorkerHandler","_removeWorkerFromList","index","removeWorker","termPromise","stats","totalWorkers","busyWorkers","filter","idleWorkers","pendingTasks","activeTasks","overriddenParams","Pool_1","Transfer","exit","parentPort","convertError","getOwnPropertyNames","reduce","product","defineProperty","enumerable","isPromise","run","args","Function","apply","cleanupAndExit","_exit","currentRequestId","register","hasOwnProperty","onTerminate","add","pool_1","src","worker_1","workerEmit_1","workerEmit","require$$4","platform_1","isMainThread_1","cpus_1"],"mappings":";uRAGA,IAAIA,EAAS,SAAUC,GACrB,YACyB,IAAhBA,GACiB,MAAxBA,EAAYC,UACiB,MAA7BD,EAAYC,SAASC,MACrBF,EAAc,IAAO,oBAGzBG,EAAAC,QAAAL,OAAwBA,EAGxBI,EAA0BC,QAAAC,SAAmB,oBAAZC,SAA2BP,EAAOO,SAC/D,OACA,UAIJ,IAAIC,EAA6C,SAA5BJ,EAAOC,QAAQC,UAAuBG,QAAQ,kBACnEL,EAAAC,QAAAK,aAA0D,SAA5BN,EAAOC,QAAQC,WACtCE,GAAkB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