{"version":3,"sources":["webpack://workerpool/./src/worker.js","webpack://workerpool/webpack/bootstrap","webpack://workerpool/webpack/startup"],"names":["requireFoolWebpack","eval","TERMINATE_METHOD_ID","worker","exit","self","postMessage","addEventListener","on","event","callback","message","data","send","process","WorkerThreads","error","code","parentPort","bind","Error","convertError","Object","getOwnPropertyNames","reduce","product","name","defineProperty","value","enumerable","isPromise","then","methods","run","fn","args","f","Function","apply","keys","currentRequestId","request","method","id","result","params","err","register","hasOwnProperty","emit","payload","isEvent","exports"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAEA;AACA,IAAIA,kBAAkB,GAAGC,IAAI,CACzB,qCACA,YADA,GAEA,gFAHyB,CAA7B;AAMA;AACA;AACA;AACA;;AACA,IAAIC,mBAAmB,GAAG,0BAA1B,C,CAEA;AAEA;AACA;;AACA,IAAIC,MAAM,GAAG;AACXC,MAAI,EAAE,gBAAW,CAAE;AADR,CAAb;;AAGA,IAAI,OAAOC,IAAP,KAAgB,WAAhB,IAA+B,OAAOC,WAAP,KAAuB,UAAtD,IAAoE,OAAOC,gBAAP,KAA4B,UAApG,EAAgH;AAC9G;AACAJ,QAAM,CAACK,EAAP,GAAY,UAAUC,KAAV,EAAiBC,QAAjB,EAA2B;AACrCH,oBAAgB,CAACE,KAAD,EAAQ,UAAUE,OAAV,EAAmB;AACzCD,cAAQ,CAACC,OAAO,CAACC,IAAT,CAAR;AACD,KAFe,CAAhB;AAGD,GAJD;;AAKAT,QAAM,CAACU,IAAP,GAAc,UAAUF,OAAV,EAAmB;AAC/BL,eAAW,CAACK,OAAD,CAAX;AACD,GAFD;AAGD,CAVD,MAWK,IAAI,OAAOG,OAAP,KAAmB,WAAvB,EAAoC;AACvC;AAEA,MAAIC,aAAJ;;AACA,MAAI;AACFA,iBAAa,GAAGf,kBAAkB,CAAC,gBAAD,CAAlC;AACD,GAFD,CAEE,OAAMgB,KAAN,EAAa;AACb,QAAI,QAAOA,KAA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AACU,IAAP,CAAY,OAAZ;AAED,CAZD;;AAcAV,MAAM,CAAC8C,IAAP,GAAc,UAAUC,OAAV,EAAmB;AAC/B,MAAIV,gBAAJ,EAAsB;AACpBrC,UAAM,CAACU,IAAP,CAAY;AACV8B,QAAE,EAAEH,gBADM;AAEVW,aAAO,EAAE,IAFC;AAGVD,aAAO,EAAPA;AAHU,KAAZ;AAKD;AACF,CARD;;AAUA,IAAI,IAAJ,EAAoC;AAClCE,2BAAA,GAAcjD,MAAM,CAAC4C,QAArB;AACAK,2BAAA,GAAejD,MAAM,CAAC8C,IAAtB;AACD,C;;;;;;UCzMD;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;UCrBA;UACA;UACA;UACA","file":"worker.js","sourcesContent":["/**\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/**\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 = 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 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\nvar currentRequestId = null;\n\nworker.on('message', function (request) {\n if (request === TERMINATE_METHOD_ID) {\n return worker.exit(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 worker.send({\n id: request.id,\n result: result,\n error: null\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 worker.send({\n id: request.id,\n result: result,\n error: null\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 */\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\nworker.emit = function (payload) {\n if (currentRequestId) {\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","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module\n__webpack_require__(744);\n// This entry module used 'exports' so it can't be inlined\n"],"sourceRoot":""}