/*! For license information please see workerpool.min.js.LICENSE.txt */ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("workerpool",[],r):"object"==typeof exports?exports.workerpool=r():e.workerpool=r()}("undefined"!=typeof self?self:this,(function(){return function(){var __webpack_modules__={345:function(e,r,t){var o=t(219),n=t(751),i=t(828),s=new(t(833));function u(e,r){"string"==typeof e?this.script=e||null:(this.script=null,r=e),this.workers=[],this.tasks=[],r=r||{},this.forkArgs=r.forkArgs||[],this.forkOpts=r.forkOpts||{},this.debugPortStart=r.debugPortStart||43210,this.nodeWorker=r.nodeWorker,this.workerType=r.workerType||r.nodeWorker||"auto",this.maxQueueSize=r.maxQueueSize||1/0,r&&"maxWorkers"in r?(function(e){if(!c(e)||!a(e)||e<1)throw new TypeError("Option maxWorkers must be an integer number >= 1")}(r.maxWorkers),this.maxWorkers=r.maxWorkers):this.maxWorkers=Math.max((i.cpus||4)-1,1),r&&"minWorkers"in r&&("max"===r.minWorkers?this.minWorkers=this.maxWorkers:(function(e){if(!c(e)||!a(e)||e<0)throw new TypeError("Option minWorkers must be an integer number >= 0")}(r.minWorkers),this.minWorkers=r.minWorkers,this.maxWorkers=Math.max(this.minWorkers,this.maxWorkers)),this._ensureMinWorkers()),this._boundNext=this._next.bind(this),"thread"===this.workerType&&n.ensureWorkerThreads()}function c(e){return"number"==typeof e}function a(e){return Math.round(e)==e}u.prototype.exec=function(e,r,t){if(r&&!Array.isArray(r))throw new TypeError('Array expected as argument "params"');if("string"==typeof e){var n=o.defer();if(this.tasks.length>=this.maxQueueSize)throw new Error("Max queue size of "+this.maxQueueSize+" reached");var i=this.tasks,s={method:e,params:r,resolver:n,timeout:null,options:t};i.push(s);var u=n.promise.timeout;return n.promise.timeout=function(e){return-1!==i.indexOf(s)?(s.timeout=e,n.promise):u.call(n.promise,e)},this._next(),n.promise}if("function"==typeof e)return this.exec("run",[String(e),r]);throw new TypeError('Function or string expected as argument "method"')},u.prototype.proxy=function(){if(arguments.length>0)throw new Error("No arguments expected");var e=this;return this.exec("methods").then((function(r){var t={};return r.forEach((function(r){t[r]=function(){return e.exec(r,Array.prototype.slice.call(arguments))}})),t}))},u.prototype._next=function(){if(this.tasks.length>0){var e=this._getWorker();if(e){var r=this,t=this.tasks.shift();if(t.resolver.promise.pending){var o=e.exec(t.method,t.params,t.resolver,t.options).then(r._boundNext).catch((function(){if(e.terminated)return r._removeWorker(e)})).then((function(){r._next()}));"number"==typeof t.timeout&&o.timeout(t.timeout)}else r._next()}}},u.prototype._getWorker=function(){for(var e=this.workers,r=0;re.length)&&(r=e.length);for(var t=0,o=new Array(r);t= 11.7.0 required");return e}function f(){if("function"!=typeof Worker&&("object"!==("undefined"==typeof Worker?"undefined":n(Worker))||"function"!=typeof Worker.prototype.constructor))throw new Error("WorkerPool: Web Workers not supported")}function p(){try{return u("worker_threads")}catch(e){if("object"===n(e)&&null!==e&&"MODULE_NOT_FOUND"===e.code)return null;throw e}}function d(e,r){var t=new r(e);return t.isBrowserWorker=!0,t.on=function(e,r){this.addEventListener(e,(function(e){r(e.data)}))},t.send=function(e){this.postMessage(e)},t}function l(e,r){var t=new r.Worker(e,{stdout:!1,stderr:!1});return t.isWorkerThread=!0,t.send=function(e){this.postMessage(e)},t.kill=function(){return this.terminate(),!0},t.disconnect=function(){this.terminate()},t}function h(e,r,t){var o=t.fork(e,r.forkArgs,r.forkOpts);return o.isChildProcess=!0,o}function k(e){e=e||{};var r=process.execArgv.join(" "),t=-1!==r.indexOf("--inspect"),o=-1!==r.indexOf("--debug-brk"),n=[];return t&&(n.push("--inspect="+e.debugPort),o&&n.push("--debug-brk")),process.execArgv.forEach((function(e){e.indexOf("--max-old-space-size")>-1&&n.push(e)})),Object.assign({},e,{forkArgs:e.forkArgs,forkOpts:Object.assign({},e.forkOpts,{execArgv:(e.forkOpts&&e.forkOpts.execArgv||[]).concat(n)})})}function w(e,r){var n=this,i=r||{};function c(e){for(var r in n.terminated=!0,n.processing)void 0!==n.processing[r]&&n.processing[r].resolver.reject(e);n.processing=Object.create(null)}this.script=e||function(){if("browser"===s.platform){if("undefined"==typeof Blob)throw new Error("Blob not supported by the browser");if(!window.URL||"function"!=typeof window.URL.createObjectURL)throw new Error("URL.createObjectURL not supported by the browser");var e=new Blob([t(670)],{type:"text/javascript"});return window.URL.createObjectURL(e)}return __dirname+"/worker.js"}(),this.worker=function(e,r){if("web"===r.workerType)return f(),d(e,Worker);if("thread"===r.workerType)return l(e,t=a());if("process"!==r.workerType&&r.workerType){if("browser"===s.platform)return f(),d(e,Worker);var t=p();return t?l(e,t):h(e,k(r),u("child_process"))}return h(e,k(r),u("child_process"))}(this.script,i),this.debugPort=i.debugPort,e||(this.worker.ready=!0),this.requestQueue=[],this.worker.on("message",(function(e){if("string"==typeof e&&"ready"===e)n.worker.ready=!0,function(){var e,r=function(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,u=!0,c=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return u=e.done,e},e:function(e){c=!0,s=e},f:function(){try{u||null==t.return||t.return()}finally{if(c)throw s}}}}(n.requestQueue.splice(0));try{for(r.s();!(e=r.n()).done;){var t=e.value;n.worker.send(t)}}catch(e){r.e(e)}finally{r.f()}}();else{var r=e.id,t=n.processing[r];void 0!==t&&(e.isEvent?t.options&&"function"==typeof t.options.on&&t.options.on(e.payload):(delete n.processing[r],!0===n.terminating&&n.terminate(),e.error?t.resolver.reject(function(e){for(var r=new Error(""),t=Object.keys(e),o=0;o0},w.prototype.terminate=function(e,r){var t=this;if(e){for(var o in this.processing)void 0!==this.processing[o]&&this.processing[o].resolver.reject(new Error("Worker terminated"));this.processing=Object.create(null)}if("function"==typeof r&&(this.terminationHandler=r),this.busy())this.terminating=!0;else{var n=function(e){if(t.terminated=!0,t.worker=null,t.terminating=!1,t.terminationHandler)t.terminationHandler(e,t);else if(e)throw e};if(this.worker){if("function"==typeof this.worker.kill){if(this.worker.killed)return void n(new Error("worker already killed!"));if(this.worker.isChildProcess){var i=setTimeout((function(){t.worker.kill()}),1e3);this.worker.once("exit",(function(){clearTimeout(i),t.worker.killed=!0,n()})),this.worker.ready?this.worker.send(c):this.worker.requestQueue.push(c)}else this.worker.kill(),this.worker.killed=!0,n();return}if("function"!=typeof this.worker.terminate)throw new Error("Failed to terminate worker");this.worker.terminate(),this.worker.killed=!0}n()}},w.prototype.terminateAndNotify=function(e,r){var t=i.defer();return r&&(t.promise.timeout=r),this.terminate(e,(function(e,r){e?t.reject(e):t.resolve(r)})),t.promise},e.exports=w,e.exports._tryRequireWorkerThreads=p,e.exports._setupProcessWorker=h,e.exports._setupBrowserWorker=d,e.exports._setupWorkerThreadWorker=l,e.exports.ensureWorkerThreads=a},833:function(e){"use strict";function r(){this.ports=Object.create(null),this.length=0}e.exports=r,r.prototype.nextAvailableStartingAt=function(e){for(;!0===this.ports[e];)e++;if(e>=65535)throw new Error("WorkerPool debug port limit reached: "+e+">= 65535");return this.ports[e]=!0,this.length++,e},r.prototype.releasePort=function(e){delete this.ports[e],this.length--}},828:function(e,r,t){var o=t(397),n=function(e){return void 0!==e&&null!=e.versions&&null!=e.versions.node};e.exports.isNode=n,e.exports.platform="undefined"!=typeof process&&n(process)?"node":"browser";var i=function(e){try{return o("worker_threads")}catch(e){return null}}();e.exports.isMainThread="node"===e.exports.platform?(!i||i.isMainThread)&&!process.connected:"undefined"!=typeof Window,e.exports.cpus="browser"===e.exports.platform?self.navigator.hardwareConcurrency:o("os").cpus().length},670:function(e){e.exports='!function(){var __webpack_modules__={744:function(__unused_webpack_module,exports){var __webpack_unused_export__;function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var requireFoolWebpack=eval("typeof require !== \'undefined\' ? require : function (module) { throw new Error(\'Module \\" + module + \\" not found.\') }"),TERMINATE_METHOD_ID="__workerpool-terminate__",worker={exit:function(){}},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(error){if("object"!==_typeof(error)||null===error||"MODULE_NOT_FOUND"!==error.code)throw error}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)}),worker.exit=process.exit.bind(process))}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(e,r){e=new Function("return ("+e+").apply(null, arguments);");return e.apply(e,r)},worker.methods.methods=function(){return Object.keys(worker.methods)};var currentRequestId=null;worker.on("message",function(r){if(r===TERMINATE_METHOD_ID)return worker.exit(0);try{var e=worker.methods[r.method];if(!e)throw new Error(\'Unknown method "\'+r.method+\'"\');currentRequestId=r.id;e=e.apply(e,r.params);isPromise(e)?e.then(function(e){worker.send({id:r.id,result:e,error:null}),currentRequestId=null}).catch(function(e){worker.send({id:r.id,result:null,error:convertError(e)}),currentRequestId=null}):(worker.send({id:r.id,result:e,error:null}),currentRequestId=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")},worker.emit=function(e){currentRequestId&&worker.send({id:currentRequestId,isEvent:!0,payload:e})},__webpack_unused_export__=worker.register,__webpack_unused_export__=worker.emit}},__webpack_module_cache__={};function __webpack_require__(e){if(__webpack_module_cache__[e])return __webpack_module_cache__[e].exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}__webpack_require__(744)}();'},352:function(e,r,t){var o=t(828);r.pool=function(e,r){return new(t(345))(e,r)},r.worker=function(e){t(744).add(e)},r.workerEmit=function(e){t(744).emit(e)},r.Promise=t(219),r.platform=o.platform,r.isMainThread=o.isMainThread,r.cpus=o.cpus},397:function(module){var requireFoolWebpack=eval("typeof require !== 'undefined' ? require : function (module) { throw new Error('Module \" + module + \" not found.') }");module.exports=requireFoolWebpack},744:function(__unused_webpack_module,exports){function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var requireFoolWebpack=eval("typeof require !== 'undefined' ? require : function (module) { throw new Error('Module \" + module + \" not found.') }"),TERMINATE_METHOD_ID="__workerpool-terminate__",worker={exit:function(){}};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");var WorkerThreads;try{WorkerThreads=requireFoolWebpack("worker_threads")}catch(e){if("object"!==_typeof(e)||null===e||"MODULE_NOT_FOUND"!==e.code)throw e}if(WorkerThreads&&null!==WorkerThreads.parentPort){var parentPort=WorkerThreads.parentPort;worker.send=parentPort.postMessage.bind(parentPort),worker.on=parentPort.on.bind(parentPort)}else worker.on=process.on.bind(process),worker.send=process.send.bind(process),worker.on("disconnect",(function(){process.exit(1)})),worker.exit=process.exit.bind(process)}function convertError(e){return Object.getOwnPropertyNames(e).reduce((function(r,t){return Object.defineProperty(r,t,{value:e[t],enumerable:!0})}),{})}function isPromise(e){return e&&"function"==typeof e.then&&"function"==typeof e.catch}worker.methods={},worker.methods.run=function(e,r){var t=new Function("return ("+e+").apply(null, arguments);");return t.apply(t,r)},worker.methods.methods=function(){return Object.keys(worker.methods)};var currentRequestId=null;worker.on("message",(function(e){if(e===TERMINATE_METHOD_ID)return worker.exit(0);try{var r=worker.methods[e.method];if(!r)throw new Error('Unknown method "'+e.method+'"');currentRequestId=e.id;var t=r.apply(r,e.params);isPromise(t)?t.then((function(r){worker.send({id:e.id,result:r,error:null}),currentRequestId=null})).catch((function(r){worker.send({id:e.id,result:null,error:convertError(r)}),currentRequestId=null})):(worker.send({id:e.id,result:t,error:null}),currentRequestId=null)}catch(r){worker.send({id:e.id,result:null,error:convertError(r)})}})),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r]);worker.send("ready")},worker.emit=function(e){currentRequestId&&worker.send({id:currentRequestId,isEvent:!0,payload:e})},exports.add=worker.register,exports.emit=worker.emit}},__webpack_module_cache__={};function __webpack_require__(e){if(__webpack_module_cache__[e])return __webpack_module_cache__[e].exports;var r=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](r,r.exports,__webpack_require__),r.exports}return __webpack_require__(352)}()})); //# sourceMappingURL=workerpool.min.js.map