{"version":3,"sources":["webpack://workerpool/webpack/universalModuleDefinition","webpack://workerpool/webpack/bootstrap","webpack://workerpool/./src/environment.js","webpack://workerpool/./src/Promise.js","webpack://workerpool/./src/requireFoolWebpack.js","webpack://workerpool/./src/index.js","webpack://workerpool/./src/Pool.js","webpack://workerpool/./src/WorkerHandler.js","webpack://workerpool/./src/generated/embeddedWorker.js","webpack://workerpool/./src/debug-port-allocator.js","webpack://workerpool/./src/worker.js"],"names":["root","factory","exports","module","define","amd","self","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","requireFoolWebpack","isNode","nodeProcess","versions","node","platform","process","worker_threads","err","tryRequireFoolWebpack","isMainThread","connected","Window","cpus","navigator","hardwareConcurrency","length","Promise","handler","parent","me","SyntaxError","_onSuccess","_onFail","resolved","rejected","pending","_process","onSuccess","onFail","push","then","resolve","reject","_then","f","_resolve","result","forEach","fn","_reject","error","cancel","CancellationError","timeout","delay","timer","setTimeout","TimeoutError","always","clearTimeout","callback","res","message","stack","Error","all","promises","remaining","results","defer","resolver","promise","constructor","eval","environment","pool","script","options","worker","methods","add","WorkerHandler","DEBUG_PORT_ALLOCATOR","Pool","workers","tasks","forkArgs","forkOpts","debugPortStart","nodeWorker","workerType","maxQueueSize","Infinity","maxWorkers","isNumber","isInteger","TypeError","validateMaxWorkers","Math","max","minWorkers","validateMinWorkers","_ensureMinWorkers","_boundNext","_next","ensureWorkerThreads","round","exec","method","params","Array","isArray","task","originalTimeout","indexOf","String","proxy","arguments","slice","_getWorker","shift","catch","terminated","_removeWorker","busy","_createWorkerHandler","releasePort","debugPort","_removeWorkerFromList","terminate","index","splice","force","removeWorker","termPromise","terminateAndNotify","stats","totalWorkers","busyWorkers","filter","idleWorkers","pendingTasks","activeTasks","nextAvailableStartingAt","WorkerThreads","tryRequireWorkerThreads","ensureWebWorker","Worker","code","setupBrowserWorker","isBrowserWorker","on","event","addEventListener","data","send","postMessage","setupWorkerThreadWorker","stdout","stderr","isWorkerThread","kill","disconnect","setupProcessWorker","child_process","fork","isChildProcess","resolveForkOptions","opts","processExecArgv","execArgv","join","inspectorActive","debugBrk","arg","assign","concat","_options","onError","id","processing","undefined","Blob","window","URL","createObjectURL","blob","type","__dirname","getDefaultWorker","setupWorker","ready","requestQueue","response","terminating","obj","temp","props","keys","objectToError","exitCode","signalCode","spawnargs","spawnfile","terminationHandler","lastId","request","cleanup","killed","once","_tryRequireWorkerThreads","_setupProcessWorker","_setupBrowserWorker","_setupWorkerThreadWorker","DebugPortAllocator","ports","starting","port","parentPort","exit","convertError","getOwnPropertyNames","reduce","product","isPromise","run","args","apply","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,aAAc,GAAIH,GACC,iBAAZC,QACdA,QAAoB,WAAID,IAExBD,EAAiB,WAAIC,IARvB,CASoB,oBAATK,KAAuBA,KAAOC,MAAO,WAChD,O,YCTE,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUR,QAGnC,IAAIC,EAASK,EAAiBE,GAAY,CACzCC,EAAGD,EACHE,GAAG,EACHV,QAAS,IAUV,OANAW,EAAQH,GAAUI,KAAKX,EAAOD,QAASC,EAAQA,EAAOD,QAASO,GAG/DN,EAAOS,GAAI,EAGJT,EAAOD,QA0Df,OArDAO,EAAoBM,EAAIF,EAGxBJ,EAAoBO,EAAIR,EAGxBC,EAAoBQ,EAAI,SAASf,EAASgB,EAAMC,GAC3CV,EAAoBW,EAAElB,EAASgB,IAClCG,OAAOC,eAAepB,EAASgB,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEV,EAAoBgB,EAA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D,EAAS8D,EAAOuH,MAAMvH,EAAQkG,EAAQjG,QAEtCmH,UAAUlL,GAEZA,EACKN,MAAK,SAAUM,GACdgC,OAAO6E,KAAK,CACVwB,GAAI2B,EAAQ3B,GACZrI,OAAQA,EACRI,MAAO,UAGVuE,OAAM,SAAUxG,GACf6D,OAAO6E,KAAK,CACVwB,GAAI2B,EAAQ3B,GACZrI,OAAQ,KACRI,MAAO0K,aAAa3M,QAM5B6D,OAAO6E,KAAK,CACVwB,GAAI2B,EAAQ3B,GACZrI,OAAQA,EACRI,MAAO,OAQf,MAAOjC,GACL6D,OAAO6E,KAAK,CACVwB,GAAI2B,EAAQ3B,GACZrI,OAAQ,KACRI,MAAO0K,aAAa3M,SAS1B6D,OAAOsJ,SAAW,SAAUrJ,GAE1B,GAAIA,EACF,IAAK,IAAI/F,KAAQ+F,EACXA,EAAQzE,eAAetB,KACzB8F,OAAOC,QAAQ/F,GAAQ+F,EAAQ/F,IAKrC8F,OAAO6E,KAAK,UAKZ3L,QAAQgH,IAAMF,OAAOsJ","file":"workerpool.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"workerpool\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"workerpool\"] = factory();\n\telse\n\t\troot[\"workerpool\"] = factory();\n})((typeof self !== 'undefined' ? self : this), function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 3);\n","var requireFoolWebpack = require('./requireFoolWebpack');\n\n// source: https://github.com/flexdinesh/browser-or-node\nvar isNode = function (nodeProcess) {\n return (\n typeof nodeProcess !== 'undefined' &&\n nodeProcess.versions != null &&\n nodeProcess.versions.node != null\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 = tryRequireFoolWebpack('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 : requireFoolWebpack('os').cpus().length;\n\nfunction tryRequireFoolWebpack (module) {\n try {\n return requireFoolWebpack(module);\n } catch(err) {\n return null\n }\n}\n","'use strict';\n\n/**\n * Promise\n *\n * Inspired by https://gist.github.com/RubaXa/8501359 from RubaXa \n *\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 this.resolved = false;\n this.rejected = false;\n this.pending = true;\n\n /**\n * Process onSuccess and onFail callbacks: add them to the queue.\n * Once the promise is resolve, 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 * @param {Function} onSuccess\n * @param {Function} [onFail]\n * @returns {Promise} 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 te promise. This will reject the promise with a CancellationError\n * @returns {Promise} 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 {Promise} 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 * @param {Function} onFail\n * @returns {Promise} 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 * @param {Function} fn\n * @returns {Promise} 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} 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\nmodule.exports = Promise;\n","// source of inspiration: https://github.com/sindresorhus/require-fool-webpack\nvar requireFoolWebpack = eval(\n 'typeof require !== \\'undefined\\' ' +\n '? require ' +\n ': function (module) { throw new Error(\\'Module \" + module + \" not found.\\') }'\n);\n\nmodule.exports = requireFoolWebpack;\n","var environment = require('./environment');\n\n/**\n * Create a new worker pool\n * @param {string} [script]\n * @param {WorkerPoolOptions} [options]\n * @returns {Pool} pool\n */\nexports.pool = function pool(script, options) {\n var Pool = require('./Pool');\n\n return new Pool(script, options);\n};\n\n/**\n * Create a worker and optionally register a set of methods to the worker.\n * @param {Object} [methods]\n */\nexports.worker = function worker(methods) {\n var worker = require('./worker');\n worker.add(methods);\n};\n\n/**\n * Create a promise.\n * @type {Promise} promise\n */\nexports.Promise = require('./Promise');\n\nexports.platform = environment.platform;\nexports.isMainThread = environment.isMainThread;\nexports.cpus = environment.cpus;","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\n * @param {String} [script] Optional worker script\n * @param {WorkerPoolOptions} [options] See docs\n * @constructor\n */\nfunction Pool(script, options) {\n if (typeof script === 'string') {\n this.script = script || null;\n }\n else {\n this.script = null;\n options = script;\n }\n\n this.workers = []; // queue with all workers\n this.tasks = []; // queue with tasks awaiting execution\n\n options = options || {};\n\n this.forkArgs = options.forkArgs || [];\n this.forkOpts = options.forkOpts || {};\n this.debugPortStart = (options.debugPortStart || 43210);\n this.nodeWorker = options.nodeWorker;\n this.workerType = options.workerType || options.nodeWorker || 'auto'\n this.maxQueueSize = options.maxQueueSize || Infinity;\n\n // configuration\n if (options && 'maxWorkers' in options) {\n validateMaxWorkers(options.maxWorkers);\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 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 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 *\n * @param {String | Function} 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 {Array} [params] Function arguments applied when calling the function\n * @return {Promise.<*, Error>} result\n */\nPool.prototype.exec = function (method, params) {\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 };\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]);\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. The methods always return a promise.\n *\n * @return {Promise.} proxy\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.} 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 * @protected\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)\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}\n * @protected\n */\nPool.prototype._removeWorker = function(worker) {\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 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 * @protected\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.}\n */\nPool.prototype.terminate = function (force, timeout) {\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 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 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 * @protected\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 return new WorkerHandler(this.script, {\n forkArgs: this.forkArgs,\n forkOpts: this.forkOpts,\n debugPort: DEBUG_PORT_ALLOCATOR.nextAvailableStartingAt(this.debugPortStart),\n workerType: this.workerType\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 Promise = require('./Promise');\nvar environment = require('./environment');\nvar requireFoolWebpack = require('./requireFoolWebpack');\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 requireFoolWebpack('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, Worker);\n } else if (options.workerType === 'thread') { // node.js only\n WorkerThreads = ensureWorkerThreads();\n return setupWorkerThreadWorker(script, WorkerThreads);\n } else if (options.workerType === 'process' || !options.workerType) { // node.js only\n return setupProcessWorker(script, resolveForkOptions(options), requireFoolWebpack('child_process'));\n } else { // options.workerType === 'auto' or undefined\n if (environment.platform === 'browser') {\n ensureWebWorker();\n return setupBrowserWorker(script, Worker);\n }\n else { // environment.platform === 'node'\n var WorkerThreads = tryRequireWorkerThreads();\n if (WorkerThreads) {\n return setupWorkerThreadWorker(script, WorkerThreads);\n } else {\n return setupProcessWorker(script, resolveForkOptions(options), requireFoolWebpack('child_process'));\n }\n }\n }\n}\n\nfunction setupBrowserWorker(script, Worker) {\n // create the web worker\n var worker = new Worker(script);\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) {\n this.postMessage(message);\n };\n return worker;\n}\n\nfunction setupWorkerThreadWorker(script, WorkerThreads) {\n var worker = new WorkerThreads.Worker(script, {\n stdout: false, // automatically pipe worker.STDOUT to process.STDOUT\n stderr: false // automatically pipe worker.STDERR to process.STDERR\n });\n worker.isWorkerThread = true;\n // make the worker mimic a child_process\n worker.send = function(message) {\n this.postMessage(message);\n };\n\n worker.kill = function() {\n this.terminate();\n return true;\n };\n\n worker.disconnect = function() {\n this.terminate();\n };\n\n return worker;\n}\n\nfunction setupProcessWorker(script, options, child_process) {\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 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 })\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\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 {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\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 this.worker.on('message', function (response) {\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 // 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 // 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 me.requestQueue.forEach(me.worker.send.bind(me.worker));\n me.requestQueue = [];\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.terminationHandler = null;\n this.lastId = 0;\n}\n\n/**\n * Get a list with methods available on the worker.\n * @return {Promise.} 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 * @return {Promise.<*, Error>} result\n */\nWorkerHandler.prototype.exec = function(method, params, resolver) {\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 };\n\n // build a JSON-RPC request\n var request = {\n id: id,\n method: method,\n params: params\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);\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 working or not\n * @return {boolean} Returns true if the worker is busy\n */\nWorkerHandler.prototype.busy = function () {\n return 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.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 // child process\n if (!this.worker.killed && !this.worker.kill()) {\n cleanup(new Error('Failed to send SIGTERM to worker'));\n } else { \n // cleanup once the child process has exited\n this.worker.once('exit', function() {\n cleanup();\n });\n }\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.}\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(o){var n={};function t(e){if(n[e])return n[e].exports;var r=n[e]={i:e,l:!1,exports:{}};return o[e].call(r.exports,r,r.exports,t),r.l=!0,r.exports}t.m=o,t.c=n,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:o})},t.r=function(e){\\\"undefined\\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\\"Module\\\"}),Object.defineProperty(e,\\\"__esModule\\\",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&\\\"object\\\"==typeof r&&r&&r.__esModule)return r;var o=Object.create(null);if(t.r(o),Object.defineProperty(o,\\\"default\\\",{enumerable:!0,value:r}),2&e&&\\\"string\\\"!=typeof r)for(var n in r)t.d(o,n,function(e){return r[e]}.bind(null,n));return o},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,\\\"a\\\",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p=\\\"\\\",t(t.s=0)}([function(module,exports,__webpack_require__){var requireFoolWebpack=eval(\\\"typeof require !== 'undefined' ? require : function (module) { throw new Error('Module \\\\\\\" + module + \\\\\\\" not found.') }\\\"),worker={},WorkerThreads,parentPort;if(\\\"undefined\\\"!=typeof self&&\\\"function\\\"==typeof postMessage&&\\\"function\\\"==typeof addEventListener)worker.on=function(e,r){addEventListener(e,function(e){r(e.data)})},worker.send=function(e){postMessage(e)};else{if(\\\"undefined\\\"==typeof process)throw new Error(\\\"Script must be executed as a worker\\\");try{WorkerThreads=requireFoolWebpack(\\\"worker_threads\\\")}catch(e){if(\\\"object\\\"!=typeof e||null===e||\\\"MODULE_NOT_FOUND\\\"!==e.code)throw e}WorkerThreads&&null!==WorkerThreads.parentPort?(parentPort=WorkerThreads.parentPort,worker.send=parentPort.postMessage.bind(parentPort),worker.on=parentPort.on.bind(parentPort)):(worker.on=process.on.bind(process),worker.send=process.send.bind(process),worker.on(\\\"disconnect\\\",function(){process.exit(1)}))}function convertError(o){return Object.getOwnPropertyNames(o).reduce(function(e,r){return Object.defineProperty(e,r,{value:o[r],enumerable:!0})},{})}function isPromise(e){return e&&\\\"function\\\"==typeof e.then&&\\\"function\\\"==typeof e.catch}worker.methods={},worker.methods.run=function run(fn,args){var f=eval(\\\"(\\\"+fn+\\\")\\\");return f.apply(f,args)},worker.methods.methods=function(){return Object.keys(worker.methods)},worker.on(\\\"message\\\",function(r){try{var e=worker.methods[r.method];if(!e)throw new Error('Unknown method \\\"'+r.method+'\\\"');e=e.apply(e,r.params);isPromise(e)?e.then(function(e){worker.send({id:r.id,result:e,error:null})}).catch(function(e){worker.send({id:r.id,result:null,error:convertError(e)})}):worker.send({id:r.id,result:e,error:null})}catch(e){worker.send({id:r.id,result:null,error:convertError(e)})}}),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r]);worker.send(\\\"ready\\\")},exports.add=worker.register}]);\";\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 * worker must be started as a child process or a web worker.\n * It listens for RPC messages from the parent process.\n */\n\n// source of inspiration: https://github.com/sindresorhus/require-fool-webpack\nvar requireFoolWebpack = eval(\n 'typeof require !== \\'undefined\\'' +\n ' ? require' +\n ' : function (module) { throw new Error(\\'Module \" + module + \" not found.\\') }'\n);\n\n// create a worker API for sending and receiving messages which works both on\n// node.js and in the browser\nvar worker = {};\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 = requireFoolWebpack('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 } else {\n worker.on = process.on.bind(process);\n worker.send = process.send.bind(process);\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 }\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 = eval('(' + fn + ')');\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\nworker.on('message', function (request) {\n try {\n var method = worker.methods[request.method];\n\n if (method) {\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 worker.send({\n id: request.id,\n result: result,\n error: null\n });\n })\n .catch(function (err) {\n worker.send({\n id: request.id,\n result: null,\n error: convertError(err)\n });\n });\n }\n else {\n // immediate result\n worker.send({\n id: request.id,\n result: result,\n error: null\n });\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 */\nworker.register = function (methods) {\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 worker.send('ready');\n\n};\n\nif (typeof exports !== 'undefined') {\n exports.add = worker.register;\n}\n"],"sourceRoot":""}