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