Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

workerpool

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workerpool - npm Package Compare versions

Comparing version
1.2.0
to
1.2.1
+8
examples/browser/require.js/index.html
<html>
<head>
<title>require.js example</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="main"></script>
</head>
<body>
</body>
</html>
define(['../../../dist/workerpool'], function(workerpool) {
'use strict';
var pool = workerpool.pool();
return pool.exec(function(value) {
return value + 1;
}, [1]).then(function(results) {
document.write('results: ' + results);
pool.clear();
});
});
+237
-116

@@ -1,127 +0,248 @@

/**
* worker must be started as a child process or a web worker.
* It listens for RPC messages from the parent process.
*/
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
var serializerr = require('serializerr')
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
// create a worker API for sending and receiving messages which works both on
// node.js and in the browser
var worker = {};
if (typeof self !== 'undefined' && typeof postMessage === 'function' && typeof addEventListener === 'function') {
// worker in the browser
worker.on = function (event, callback) {
addEventListener(event, function (message) {
callback(message.data);
})
};
worker.send = function (message) {
postMessage(message);
};
}
else if (typeof process !== 'undefined') {
// node.js
worker.on = process.on.bind(process);
worker.send = process.send.bind(process);
}
else {
throw new Error('Script must be executed as a worker');
}
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/**
* Test whether a value is a Promise via duck typing.
* @param {*} value
* @returns {boolean} Returns true when given value is an object
* having functions `then` and `catch`.
*/
function isPromise(value) {
return value && (typeof value.then === 'function') && (typeof value.catch === 'function');
}
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
// functions available externally
worker.methods = {};
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/**
* Execute a function with provided arguments
* @param {String} fn Stringified function
* @param {Array} [args] Function arguments
* @returns {*}
*/
worker.methods.run = function run(fn, args) {
var f = eval('(' + fn + ')');
return f.apply(f, args);
};
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/**
* Get a list with methods available on this worker
* @return {String[]} methods
*/
worker.methods.methods = function methods() {
return Object.keys(worker.methods);
};
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
worker.on('message', function (request) {
try {
var method = worker.methods[request.method];
if (method) {
// execute the function
var result = method.apply(method, request.params);
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
if (isPromise(result)) {
// promise returned, resolve this and then return
result
.then(function (result) {
worker.send({
id: request.id,
result: result,
error: null
});
})
.catch(function (err) {
worker.send({
id: request.id,
result: null,
error: serializerr(err)
});
});
}
else {
// immediate result
worker.send({
id: request.id,
result: result,
error: null
});
}
}
else {
throw new Error('Unknown method "' + request.method + '"');
}
}
catch (err) {
worker.send({
id: request.id,
result: null,
error: serializerr(err)
});
}
});
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/**
* Register methods to the worker
* @param {Object} methods
*/
worker.register = function (methods) {
if (methods) {
for (var name in methods) {
if (methods.hasOwnProperty(name)) {
worker.methods[name] = methods[name];
}
}
}
};
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
if (typeof exports !== 'undefined') {
exports.add = worker.register;
}
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/**
* worker must be started as a child process or a web worker.
* It listens for RPC messages from the parent process.
*/
var serializerr = __webpack_require__(1);
// create a worker API for sending and receiving messages which works both on
// node.js and in the browser
var worker = {};
if (typeof self !== 'undefined' && typeof postMessage === 'function' && typeof addEventListener === 'function') {
// worker in the browser
worker.on = function (event, callback) {
addEventListener(event, function (message) {
callback(message.data);
})
};
worker.send = function (message) {
postMessage(message);
};
}
else if (typeof process !== 'undefined') {
// node.js
worker.on = process.on.bind(process);
worker.send = process.send.bind(process);
}
else {
throw new Error('Script must be executed as a worker');
}
/**
* Test whether a value is a Promise via duck typing.
* @param {*} value
* @returns {boolean} Returns true when given value is an object
* having functions `then` and `catch`.
*/
function isPromise(value) {
return value && (typeof value.then === 'function') && (typeof value.catch === 'function');
}
// functions available externally
worker.methods = {};
/**
* Execute a function with provided arguments
* @param {String} fn Stringified function
* @param {Array} [args] Function arguments
* @returns {*}
*/
worker.methods.run = function run(fn, args) {
var f = eval('(' + fn + ')');
return f.apply(f, args);
};
/**
* Get a list with methods available on this worker
* @return {String[]} methods
*/
worker.methods.methods = function methods() {
return Object.keys(worker.methods);
};
worker.on('message', function (request) {
try {
var method = worker.methods[request.method];
if (method) {
// execute the function
var result = method.apply(method, request.params);
if (isPromise(result)) {
// promise returned, resolve this and then return
result
.then(function (result) {
worker.send({
id: request.id,
result: result,
error: null
});
})
.catch(function (err) {
worker.send({
id: request.id,
result: null,
error: serializerr(err)
});
});
}
else {
// immediate result
worker.send({
id: request.id,
result: result,
error: null
});
}
}
else {
throw new Error('Unknown method "' + request.method + '"');
}
}
catch (err) {
worker.send({
id: request.id,
result: null,
error: serializerr(err)
});
}
});
/**
* Register methods to the worker
* @param {Object} methods
*/
worker.register = function (methods) {
if (methods) {
for (var name in methods) {
if (methods.hasOwnProperty(name)) {
worker.methods[name] = methods[name];
}
}
}
};
if (true) {
exports.add = worker.register;
}
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _protochain = __webpack_require__(2);
var _protochain2 = _interopRequireDefault(_protochain);
function serializerr() {
var obj = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var chain = (0, _protochain2['default'])(obj).filter(function (obj) {
return obj !== Object.prototype;
});
return [obj].concat(chain).map(function (item) {
return Object.getOwnPropertyNames(item);
}).reduce(function (result, names) {
names.forEach(function (name) {
return result[name] = obj[name];
});
return result;
}, {});
}
module.exports = serializerr;
serializerr.serializerr = serializerr;
exports['default'] = serializerr;
module.exports = exports['default'];
/***/ },
/* 2 */
/***/ function(module, exports) {
"use strict";
module.exports = protochain;
function protochain(obj) {
var result = [];
var target = getPrototypeOf(obj);
while (target) {
result.push(target);
target = getPrototypeOf(target);
}
return result;
}
function getPrototypeOf(obj) {
if (obj == null) {
return obj;
}if (isPrimitive(obj)) obj = Object(obj);
return Object.getPrototypeOf(obj);
}
function isPrimitive(item) {
return item === null || typeof item !== "object" && typeof item !== "function";
}
/***/ }
/******/ ]);

@@ -7,7 +7,7 @@ /**

*
* @version 1.2.0
* @date 2016-05-22
* @version 1.2.1
* @date 2016-06-25
*
* @license
* Copyright (C) 2014 Jos de Jong <wjosdejong@gmail.com>
* Copyright (C) 2014-2016 Jos de Jong <wjosdejong@gmail.com>
*

@@ -29,10 +29,10 @@ * Licensed under the Apache License, Version 2.0 (the "License"); you may not

if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("child_process"), require("os"));
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define(["child_process", "os"], factory);
define([], factory);
else if(typeof exports === 'object')
exports["workerpool"] = factory(require("child_process"), require("os"));
exports["workerpool"] = factory();
else
root["workerpool"] = factory(root["child_process"], root["os"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_7__) {
root["workerpool"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap

@@ -107,3 +107,3 @@ /******/ // The module cache

// use embedded worker.js
var blob = new Blob([__webpack_require__(5)], {type: 'text/javascript'});
var blob = new Blob([__webpack_require__(6)], {type: 'text/javascript'});
var url = window.URL.createObjectURL(blob);

@@ -135,2 +135,5 @@ importScripts(url);

// used to prevent webpack from resolving requires on node libs
var node = {require: __webpack_require__(5)};
/**

@@ -160,3 +163,4 @@ * A pool to manage workers

var environment = __webpack_require__(4);
var numCPUs = (environment == 'browser') ? 4 : __webpack_require__(7).cpus().length;
// call node.require to prevent os to be required when loading with AMD
var numCPUs = (environment == 'browser') ? 4 : node.require('os').cpus().length;
this.maxWorkers = Math.max(numCPUs - 1, 1);

@@ -687,2 +691,5 @@ }

// used to prevent webpack from resolving requires on node libs
var node = {require: __webpack_require__(5)};
// get the default worker script

@@ -700,3 +707,3 @@ function getDefaultWorker() {

// use embedded worker.js
var blob = new Blob([__webpack_require__(5)], {type: 'text/javascript'});
var blob = new Blob([__webpack_require__(6)], {type: 'text/javascript'});
return window.URL.createObjectURL(blob);

@@ -757,3 +764,4 @@ }

// on node.js, create a child process
this.worker = __webpack_require__(6).fork(this.script);
// call node.require to prevent child_process to be required when loading with AMD
this.worker = node.require('child_process').fork(this.script);
}

@@ -936,2 +944,36 @@

/* 5 */
/***/ function(module, exports, __webpack_require__) {
var map = {
"./Pool": 1,
"./Pool.js": 1,
"./Promise": 2,
"./Promise.js": 2,
"./WorkerHandler": 3,
"./WorkerHandler.js": 3,
"./environment": 4,
"./environment.js": 4,
"./generated/embeddedWorker": 6,
"./generated/embeddedWorker.js": 6,
"./header": 7,
"./header.js": 7,
"./worker": 8,
"./worker.js": 8
};
function webpackContext(req) {
return __webpack_require__(webpackContextResolve(req));
};
function webpackContextResolve(req) {
return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
};
webpackContext.keys = function webpackContextKeys() {
return Object.keys(map);
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
webpackContext.id = 5;
/***/ },
/* 6 */
/***/ function(module, exports) {

@@ -944,17 +986,35 @@

*/
module.exports = "function isPromise(r){return r&&\"function\"==typeof r.then&&\"function\"==typeof r[\"catch\"]}var serializerr=require(\"serializerr\"),worker={};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\");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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+'\"');var o=e.apply(e,r.params);isPromise(o)?o.then(function(e){worker.send({id:r.id,result:e,error:null})})[\"catch\"](function(e){worker.send({id:r.id,result:null,error:serializerr(e)})}):worker.send({id:r.id,result:o,error:null})}catch(n){worker.send({id:r.id,result:null,error:serializerr(n)})}}),worker.register=function(r){if(r)for(var e in r)r.hasOwnProperty(e)&&(worker.methods[e]=r[e])},\"undefined\"!=typeof exports&&(exports.add=worker.register);";
module.exports = "!function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p=\"\",r(0)}([function(module,exports,__webpack_require__){function isPromise(e){return e&&\"function\"==typeof e.then&&\"function\"==typeof e[\"catch\"]}var serializerr=__webpack_require__(1),worker={};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\");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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(e){try{var r=worker.methods[e.method];if(!r)throw new Error('Unknown method \"'+e.method+'\"');var t=r.apply(r,e.params);isPromise(t)?t.then(function(r){worker.send({id:e.id,result:r,error:null})})[\"catch\"](function(r){worker.send({id:e.id,result:null,error:serializerr(r)})}):worker.send({id:e.id,result:t,error:null})}catch(n){worker.send({id:e.id,result:null,error:serializerr(n)})}}),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r])},exports.add=worker.register},function(e,r,t){\"use strict\";function n(e){return e&&e.__esModule?e:{\"default\":e}}function o(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=(0,u[\"default\"])(e).filter(function(e){return e!==Object.prototype});return[e].concat(r).map(function(e){return Object.getOwnPropertyNames(e)}).reduce(function(r,t){return t.forEach(function(t){return r[t]=e[t]}),r},{})}Object.defineProperty(r,\"__esModule\",{value:!0});var s=t(2),u=n(s);e.exports=o,o.serializerr=o,r[\"default\"]=o,e.exports=r[\"default\"]},function(e,r){\"use strict\";function t(e){for(var r=[],t=n(e);t;)r.push(t),t=n(t);return r}function n(e){return null==e?e:(o(e)&&(e=Object(e)),Object.getPrototypeOf(e))}function o(e){return null===e||\"object\"!=typeof e&&\"function\"!=typeof e}e.exports=t}]);";
/***/ },
/* 6 */
/* 7 */
/***/ function(module, exports) {
module.exports = require("child_process");
/**
* workerpool.js
* https://github.com/josdejong/workerpool
*
* Offload tasks to a pool of workers on node.js and in the browser.
*
* @version @@version
* @date @@date
*
* @license
* Copyright (C) 2014-2016 Jos de Jong <wjosdejong@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
/***/ },
/* 7 */
/***/ function(module, exports) {
module.exports = require("os");
/***/ },

@@ -969,3 +1029,3 @@ /* 8 */

var serializerr = __webpack_require__(9)
var serializerr = __webpack_require__(9);

@@ -972,0 +1032,0 @@ // create a worker API for sending and receiving messages which works both on

@@ -1,1 +0,1 @@

{"version":3,"sources":["./dist/workerpool.js"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE_6__","__WEBPACK_EXTERNAL_MODULE_7__","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","window","pool","script","options","Pool","worker","methods","environment","blob","Blob","type","url","URL","createObjectURL","importScripts","add","Promise","isNumber","maxWorkers","isInteger","TypeError","numCPUs","cpus","length","Math","max","workers","tasks","value","round","WorkerHandler","prototype","exec","method","params","Array","isArray","resolver","defer","push","_next","promise","String","proxy","arguments","Error","then","forEach","slice","_getWorker","me","task","shift","pending","terminated","_removeWorker","i","ii","busy","terminate","index","indexOf","splice","clear","force","handler","parent","SyntaxError","_onSuccess","_onFail","resolved","rejected","_process","onSuccess","onFail","resolve","reject","s","_then","f","_resolve","result","fn","_reject","error","cancel","CancellationError","timeout","delay","timer","setTimeout","TimeoutError","always","clearTimeout","callback","res","message","stack","all","promises","remaining","results","constructor","name","getDefaultWorker","__dirname","objectToError","obj","temp","props","Object","keys","onError","processing","hasOwnProperty","Worker","on","event","addEventListener","data","send","postMessage","fork","response","terminating","lastId","request","kill","isPromise","serializerr","self","process","bind","run","args","eval","apply","err","register","_interopRequireDefault","__esModule","default","undefined","chain","_protochain2","filter","concat","map","item","getOwnPropertyNames","reduce","names","defineProperty","_protochain","protochain","target","getPrototypeOf","isPrimitive"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;CAyBA,SAA2CA,EAAMC,GAC1B,gBAAZC,UAA0C,gBAAXC,QACxCA,OAAOD,QAAUD,EAAQG,QAAQ,iBAAkBA,QAAQ,OAClC,kBAAXC,SAAyBA,OAAOC,IAC9CD,QAAQ,gBAAiB,MAAOJ,GACN,gBAAZC,SACdA,QAAoB,WAAID,EAAQG,QAAQ,iBAAkBA,QAAQ,OAElEJ,EAAiB,WAAIC,EAAQD,EAAoB,cAAGA,EAAS,KAC5DO,KAAM,SAASC,8BAA+BC,+BACjD,MAAgB,UAAUC,GAKhB,QAASC,GAAoBC,GAG5B,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C,EAAejD,GACrBgD,GACL1E,EAAO1C,KAAKoH,GACZA,EAASC,EAAeD,EAG1B,OAAO1E,GAGT,QAAS2E,GAAejD,GACtB,MAAW,OAAPA,EACKA,GACJkD,EAAYlD,KAAMA,EAAMG,OAAOH,IAC7BG,OAAO8C,eAAejD,IAG/B,QAASkD,GAAYT,GACnB,MAAgB,QAATA,GAAiC,gBAATA,IAAqC,kBAATA,GArB7DrK,EAAOD,QAAU4K","file":"workerpool.map"}
{"version":3,"sources":["./dist/workerpool.js"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","id","loaded","call","m","c","p","window","pool","script","options","Pool","worker","methods","environment","blob","Blob","type","url","URL","createObjectURL","importScripts","add","Promise","isNumber","maxWorkers","isInteger","TypeError","numCPUs","node","require","cpus","length","Math","max","workers","tasks","value","round","WorkerHandler","prototype","exec","method","params","Array","isArray","resolver","defer","push","_next","promise","String","proxy","arguments","Error","then","forEach","slice","_getWorker","me","task","shift","pending","terminated","_removeWorker","i","ii","busy","terminate","index","indexOf","splice","clear","force","handler","parent","SyntaxError","_onSuccess","_onFail","resolved","rejected","_process","onSuccess","onFail","resolve","reject","s","_then","f","_resolve","result","fn","_reject","error","cancel","CancellationError","timeout","delay","timer","setTimeout","TimeoutError","always","clearTimeout","callback","res","message","stack","all","promises","remaining","results","constructor","name","getDefaultWorker","__dirname","objectToError","obj","temp","props","Object","keys","onError","processing","hasOwnProperty","Worker","on","event","addEventListener","data","send","postMessage","fork","response","terminating","lastId","request","kill","webpackContext","req","webpackContextResolve","map","./Pool","./Pool.js","./Promise","./Promise.js","./WorkerHandler","./WorkerHandler.js","./environment","./environment.js","./generated/embeddedWorker","./generated/embeddedWorker.js","./header","./header.js","./worker","./worker.js","isPromise","serializerr","self","process","bind","run","args","eval","apply","err","register","_interopRequireDefault","__esModule","default","undefined","chain","_protochain2","filter","concat","item","getOwnPropertyNames","reduce","names","defineProperty","_protochain","protochain","target","getPrototypeOf","isPrimitive"],"mappings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Q8B,IAAMV,OAAOyJ,UAMlB,SAAS5K,EAAQD,EAASM,GAE/B,YAMA,SAASwK,GAAuBlD,GAAO,MAAOA,IAAOA,EAAImD,WAAanD,GAAQoD,UAAWpD,GAMzF,QAASwC,KACP,GAAIxC,GAAM/D,UAAUrB,QAAU,GAAsByI,SAAjBpH,UAAU,MAAwBA,UAAU,GAE3EqH,GAAQ,EAAIC,EAAa,YAAYvD,GAAKwD,OAAO,SAAUxD,GAC7D,MAAOA,KAAQG,OAAO/E,WAExB,QAAQ4E,GAAKyD,OAAOH,GAAO9B,IAAI,SAAUkC,GACvC,MAAOvD,QAAOwD,oBAAoBD,KACjCE,OAAO,SAAUtF,EAAQuF,GAI1B,MAHAA,GAAMzH,QAAQ,SAAUwD,GACtB,MAAOtB,GAAOsB,GAAQI,EAAIJ,KAErBtB,OAtBX6B,OAAO2D,eAAe1L,EAAS,cAC7B6C,OAAO,GAKT,IAAI8I,GAAcrL,EAAoB,IAElC6K,EAAeL,EAAuBa,EAkB1C1L,GAAOD,QAAUoK,EACjBA,EAAYA,YAAcA,EAC1BpK,EAAQ,WAAaoK,EACrBnK,EAAOD,QAAUA,EAAQ,YAMpB,SAASC,EAAQD,GAEtB,YAIA,SAAS4L,GAAWhE,GAGlB,IAFA,GAAI1B,MACA2F,EAASC,EAAelE,GACrBiE,GACL3F,EAAO1C,KAAKqI,GACZA,EAASC,EAAeD,EAG1B,OAAO3F,GAGT,QAAS4F,GAAelE,GACtB,MAAW,OAAPA,EACKA,GACJmE,EAAYnE,KAAMA,EAAMG,OAAOH,IAC7BG,OAAO+D,eAAelE,IAG/B,QAASmE,GAAYT,GACnB,MAAgB,QAATA,GAAiC,gBAATA,IAAqC,kBAATA,GArB7DrL,EAAOD,QAAU4L","file":"workerpool.map"}

@@ -7,7 +7,7 @@ /**

*
* @version 1.2.0
* @date 2016-05-22
* @version 1.2.1
* @date 2016-06-25
*
* @license
* Copyright (C) 2014 Jos de Jong <wjosdejong@gmail.com>
* Copyright (C) 2014-2016 Jos de Jong <wjosdejong@gmail.com>
*

@@ -26,4 +26,3 @@ * Licensed under the Apache License, Version 2.0 (the "License"); you may not

*/
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("child_process"),require("os")):"function"==typeof define&&define.amd?define(["child_process","os"],e):"object"==typeof exports?exports.workerpool=e(require("child_process"),require("os")):r.workerpool=e(r.child_process,r.os)}(this,function(__WEBPACK_EXTERNAL_MODULE_6__,__WEBPACK_EXTERNAL_MODULE_7__){return function(r){function e(o){if(t[o])return t[o].exports;var n=t[o]={exports:{},id:o,loaded:!1};return r[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var t={};return e.m=r,e.c=t,e.p="",e(0)}([function(r,e,t){"undefined"!=typeof window;e.pool=function(r,e){var o=t(1);return new o(r,e)},e.worker=function o(r){var e=t(4);if("browser"==e){var n=new Blob([t(5)],{type:"text/javascript"}),i=window.URL.createObjectURL(n);importScripts(i)}else var o=t(8);o.add(r)},e.Promise=t(2)},function(r,e,t){function o(r,e){if("string"==typeof r?this.script=r||null:(this.script=null,e=r),e&&"maxWorkers"in e){if(!n(e.maxWorkers)||!i(e.maxWorkers)||e.maxWorkers<1)throw new TypeError("Option maxWorkers must be a positive integer number");this.maxWorkers=e.maxWorkers}else{var o=t(4),s="browser"==o?4:t(7).cpus().length;this.maxWorkers=Math.max(s-1,1)}this.workers=[],this.tasks=[]}function n(r){return"number"==typeof r}function i(r){return Math.round(r)==r}var s=t(2),c=t(3);o.prototype.exec=function(r,e){if(e&&!Array.isArray(e))throw new TypeError('Array expected as argument "params"');if("string"==typeof r){var t=s.defer();return this.tasks.push({method:r,params:e,resolver:t}),this._next(),t.promise}if("function"==typeof r)return this.exec("run",[String(r),e]);throw new TypeError('Function or string expected as argument "method"')},o.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})},o.prototype._next=function(){if(this.tasks.length>0){var r=this._getWorker();if(r){var e=this,t=this.tasks.shift();t.resolver.promise.pending&&r.exec(t.method,t.params,t.resolver).then(function(){e._next()})["catch"](function(){r.terminated&&e._removeWorker(r),e._next()})}}},o.prototype._getWorker=function(){for(var r=0,e=this.workers.length;e>r;r++){var t=this.workers[r];if(!t.busy())return t}return this.workers.length<this.maxWorkers?(t=new c(this.script),this.workers.push(t),t):null},o.prototype._removeWorker=function(r){r.terminate();var e=this.workers.indexOf(r);-1!=e&&this.workers.splice(e,1)},o.prototype.clear=function(r){this.workers.forEach(function(e){e.terminate(r)}),this.workers=[]},r.exports=o},function(r,e){"use strict";function t(r,e){var s=this;if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof r)throw new SyntaxError("Function parameter handler(resolve, reject) missing");var c=[],u=[];this.resolved=!1,this.rejected=!1,this.pending=!0;var f=function(r,e){c.push(r),u.push(e)};this.then=function(r,e){return new t(function(t,n){var i=r?o(r,t,n):t,s=e?o(e,t,n):n;f(i,s)},s)};var a=function(r){return s.resolved=!0,s.rejected=!1,s.pending=!1,c.forEach(function(e){e(r)}),f=function(e,t){e(r)},a=p=function(){throw new Error("Promise is already resolved")},s},p=function(r){return s.resolved=!1,s.rejected=!0,s.pending=!1,u.forEach(function(e){e(r)}),f=function(e,t){t(r)},a=p=function(){throw new Error("Promise is already resolved")},s};this.cancel=function(){return e?e.cancel():p(new n),s},this.timeout=function(r){if(e)e.timeout(r);else{var t=setTimeout(function(){p(new i("Promise timed out after "+r+" ms"))},r);s.always(function(){clearTimeout(t)})}return s},r(function(r){a(r)},function(r){p(r)})}function o(r,e,t){return function(o){try{var n=r(o);n&&"function"==typeof n.then&&"function"==typeof n["catch"]?n.then(e,t):e(n)}catch(i){t(i)}}}function n(r){this.message=r||"promise cancelled",this.stack=(new Error).stack}function i(r){this.message=r||"timeout exceeded",this.stack=(new Error).stack}t.prototype["catch"]=function(r){return this.then(null,r)},t.prototype.always=function(r){return this.then(r,r)},t.all=function(r){return new t(function(e,t){var o=r.length,n=[];o?r.forEach(function(r,i){r.then(function(r){n[i]=r,o--,0==o&&e(n)},function(r){o=0,t(r)})}):e(n)})},t.defer=function(){var r={};return r.promise=new t(function(e,t){r.resolve=e,r.reject=t}),r},n.prototype=new Error,n.prototype.constructor=Error,n.prototype.name="CancellationError",t.CancellationError=n,i.prototype=new Error,i.prototype.constructor=Error,i.prototype.name="TimeoutError",t.TimeoutError=i,r.exports=t},function(r,e,t){function o(){if("browser"==c){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(5)],{type:"text/javascript"});return window.URL.createObjectURL(r)}return __dirname+"/worker.js"}function n(r){for(var e=new Error(""),t=Object.keys(r),o=0;o<t.length;o++)e[t[o]]=r[t[o]];return e}function i(r){function e(r){i.terminated=!0;for(var e in i.processing)i.processing.hasOwnProperty(e)&&i.processing[e].resolver.reject(r);i.processing={}}if(this.script=r||o(),"browser"==c){if("function"!=typeof Worker)throw new Error("Web workers not supported by the browser");this.worker=new Worker(this.script),this.worker.on=function(r,e){this.addEventListener(r,function(r){e(r.data)})},this.worker.send=function(r){this.postMessage(r)}}else this.worker=t(6).fork(this.script);var i=this;this.worker.on("message",function(r){var e=r.id,t=i.processing[e];t&&(delete i.processing[e],i.terminating&&i.terminate(),r.error?t.resolver.reject(n(r.error)):t.resolver.resolve(r.result))}),this.worker.on("error",e),this.worker.on("exit",function(){var r=new Error("Worker terminated unexpectedly");e(r)}),this.processing={},this.terminating=!1,this.terminated=!1,this.lastId=0}var s=t(2),c=t(4);i.prototype.methods=function(){return this.exec("methods")},i.prototype.exec=function(r,e,t){t||(t=s.defer());var o=++this.lastId;this.processing[o]={id:o,resolver:t};var n={id:o,method:r,params:e};this.terminated?t.reject(new Error("Worker is terminated")):this.worker.send(n);var i=this;return t.promise["catch"](function(r){(r instanceof s.CancellationError||r instanceof s.TimeoutError)&&(delete i.processing[o],i.terminate(!0))}),t.promise},i.prototype.busy=function(){return Object.keys(this.processing).length>0},i.prototype.terminate=function(r){if(r){for(var e in this.processing)this.processing.hasOwnProperty(e)&&this.processing[e].resolver.reject(new Error("Worker terminated"));this.processing={}}if(this.busy())this.terminating=!0;else{if(this.worker){if("function"==typeof this.worker.kill)this.worker.kill();else{if("function"!=typeof this.worker.terminate)throw new Error("Failed to terminate worker");this.worker.terminate()}this.worker=null}this.terminating=!1,this.terminated=!0}},r.exports=i},function(r,e){r.exports="undefined"!=typeof window?"browser":"node"},function(r,e){r.exports='function isPromise(r){return r&&"function"==typeof r.then&&"function"==typeof r["catch"]}var serializerr=require("serializerr"),worker={};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");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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+\'"\');var o=e.apply(e,r.params);isPromise(o)?o.then(function(e){worker.send({id:r.id,result:e,error:null})})["catch"](function(e){worker.send({id:r.id,result:null,error:serializerr(e)})}):worker.send({id:r.id,result:o,error:null})}catch(n){worker.send({id:r.id,result:null,error:serializerr(n)})}}),worker.register=function(r){if(r)for(var e in r)r.hasOwnProperty(e)&&(worker.methods[e]=r[e])},"undefined"!=typeof exports&&(exports.add=worker.register);'},function(r,e){r.exports=require("child_process")},function(r,e){r.exports=require("os")},function(module,exports,__webpack_require__){function isPromise(r){return r&&"function"==typeof r.then&&"function"==typeof r["catch"]}var serializerr=__webpack_require__(9),worker={};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");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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+'"');var t=e.apply(e,r.params);isPromise(t)?t.then(function(e){worker.send({id:r.id,result:e,error:null})})["catch"](function(e){worker.send({id:r.id,result:null,error:serializerr(e)})}):worker.send({id:r.id,result:t,error:null})}catch(o){worker.send({id:r.id,result:null,error:serializerr(o)})}}),worker.register=function(r){if(r)for(var e in r)r.hasOwnProperty(e)&&(worker.methods[e]=r[e])},exports.add=worker.register},function(r,e,t){"use strict";function o(r){return r&&r.__esModule?r:{"default":r}}function n(){var r=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=(0,s["default"])(r).filter(function(r){return r!==Object.prototype});return[r].concat(e).map(function(r){return Object.getOwnPropertyNames(r)}).reduce(function(e,t){return t.forEach(function(t){return e[t]=r[t]}),e},{})}Object.defineProperty(e,"__esModule",{value:!0});var i=t(10),s=o(i);r.exports=n,n.serializerr=n,e["default"]=n,r.exports=e["default"]},function(r,e){"use strict";function t(r){for(var e=[],t=o(r);t;)e.push(t),t=o(t);return e}function o(r){return null==r?r:(n(r)&&(r=Object(r)),Object.getPrototypeOf(r))}function n(r){return null===r||"object"!=typeof r&&"function"!=typeof r}r.exports=t}])});
//# sourceMappingURL=workerpool.map
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.workerpool=r():e.workerpool=r()}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"undefined"!=typeof window;r.pool=function(e,r){var n=t(1);return new n(e,r)},r.worker=function n(e){var r=t(4);if("browser"==r){var o=new Blob([t(6)],{type:"text/javascript"}),i=window.URL.createObjectURL(o);importScripts(i)}else var n=t(8);n.add(e)},r.Promise=t(2)},function(e,r,t){function n(e,r){if("string"==typeof e?this.script=e||null:(this.script=null,r=e),r&&"maxWorkers"in r){if(!o(r.maxWorkers)||!i(r.maxWorkers)||r.maxWorkers<1)throw new TypeError("Option maxWorkers must be a positive integer number");this.maxWorkers=r.maxWorkers}else{var n=t(4),s="browser"==n?4:c.require("os").cpus().length;this.maxWorkers=Math.max(s-1,1)}this.workers=[],this.tasks=[]}function o(e){return"number"==typeof e}function i(e){return Math.round(e)==e}var s=t(2),u=t(3),c={require:t(5)};n.prototype.exec=function(e,r){if(r&&!Array.isArray(r))throw new TypeError('Array expected as argument "params"');if("string"==typeof e){var t=s.defer();return this.tasks.push({method:e,params:r,resolver:t}),this._next(),t.promise}if("function"==typeof e)return this.exec("run",[String(e),r]);throw new TypeError('Function or string expected as argument "method"')},n.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})},n.prototype._next=function(){if(this.tasks.length>0){var e=this._getWorker();if(e){var r=this,t=this.tasks.shift();t.resolver.promise.pending&&e.exec(t.method,t.params,t.resolver).then(function(){r._next()})["catch"](function(){e.terminated&&r._removeWorker(e),r._next()})}}},n.prototype._getWorker=function(){for(var e=0,r=this.workers.length;r>e;e++){var t=this.workers[e];if(!t.busy())return t}return this.workers.length<this.maxWorkers?(t=new u(this.script),this.workers.push(t),t):null},n.prototype._removeWorker=function(e){e.terminate();var r=this.workers.indexOf(e);-1!=r&&this.workers.splice(r,1)},n.prototype.clear=function(e){this.workers.forEach(function(r){r.terminate(e)}),this.workers=[]},e.exports=n},function(e,r){"use strict";function t(e,r){var s=this;if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof e)throw new SyntaxError("Function parameter handler(resolve, reject) missing");var u=[],c=[];this.resolved=!1,this.rejected=!1,this.pending=!0;var f=function(e,r){u.push(e),c.push(r)};this.then=function(e,r){return new t(function(t,o){var i=e?n(e,t,o):t,s=r?n(r,t,o):o;f(i,s)},s)};var a=function(e){return s.resolved=!0,s.rejected=!1,s.pending=!1,u.forEach(function(r){r(e)}),f=function(r,t){r(e)},a=p=function(){throw new Error("Promise is already resolved")},s},p=function(e){return s.resolved=!1,s.rejected=!0,s.pending=!1,c.forEach(function(r){r(e)}),f=function(r,t){t(e)},a=p=function(){throw new Error("Promise is already resolved")},s};this.cancel=function(){return r?r.cancel():p(new o),s},this.timeout=function(e){if(r)r.timeout(e);else{var t=setTimeout(function(){p(new i("Promise timed out after "+e+" ms"))},e);s.always(function(){clearTimeout(t)})}return s},e(function(e){a(e)},function(e){p(e)})}function n(e,r,t){return function(n){try{var o=e(n);o&&"function"==typeof o.then&&"function"==typeof o["catch"]?o.then(r,t):r(o)}catch(i){t(i)}}}function o(e){this.message=e||"promise cancelled",this.stack=(new Error).stack}function i(e){this.message=e||"timeout exceeded",this.stack=(new Error).stack}t.prototype["catch"]=function(e){return this.then(null,e)},t.prototype.always=function(e){return this.then(e,e)},t.all=function(e){return new t(function(r,t){var n=e.length,o=[];n?e.forEach(function(e,i){e.then(function(e){o[i]=e,n--,0==n&&r(o)},function(e){n=0,t(e)})}):r(o)})},t.defer=function(){var e={};return e.promise=new t(function(r,t){e.resolve=r,e.reject=t}),e},o.prototype=new Error,o.prototype.constructor=Error,o.prototype.name="CancellationError",t.CancellationError=o,i.prototype=new Error,i.prototype.constructor=Error,i.prototype.name="TimeoutError",t.TimeoutError=i,e.exports=t},function(e,r,t){function n(){if("browser"==u){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(6)],{type:"text/javascript"});return window.URL.createObjectURL(e)}return __dirname+"/worker.js"}function o(e){for(var r=new Error(""),t=Object.keys(e),n=0;n<t.length;n++)r[t[n]]=e[t[n]];return r}function i(e){function r(e){t.terminated=!0;for(var r in t.processing)t.processing.hasOwnProperty(r)&&t.processing[r].resolver.reject(e);t.processing={}}if(this.script=e||n(),"browser"==u){if("function"!=typeof Worker)throw new Error("Web workers not supported by the browser");this.worker=new Worker(this.script),this.worker.on=function(e,r){this.addEventListener(e,function(e){r(e.data)})},this.worker.send=function(e){this.postMessage(e)}}else this.worker=c.require("child_process").fork(this.script);var t=this;this.worker.on("message",function(e){var r=e.id,n=t.processing[r];n&&(delete t.processing[r],t.terminating&&t.terminate(),e.error?n.resolver.reject(o(e.error)):n.resolver.resolve(e.result))}),this.worker.on("error",r),this.worker.on("exit",function(){var e=new Error("Worker terminated unexpectedly");r(e)}),this.processing={},this.terminating=!1,this.terminated=!1,this.lastId=0}var s=t(2),u=t(4),c={require:t(5)};i.prototype.methods=function(){return this.exec("methods")},i.prototype.exec=function(e,r,t){t||(t=s.defer());var n=++this.lastId;this.processing[n]={id:n,resolver:t};var o={id:n,method:e,params:r};this.terminated?t.reject(new Error("Worker is terminated")):this.worker.send(o);var i=this;return t.promise["catch"](function(e){(e instanceof s.CancellationError||e instanceof s.TimeoutError)&&(delete i.processing[n],i.terminate(!0))}),t.promise},i.prototype.busy=function(){return Object.keys(this.processing).length>0},i.prototype.terminate=function(e){if(e){for(var r in this.processing)this.processing.hasOwnProperty(r)&&this.processing[r].resolver.reject(new Error("Worker terminated"));this.processing={}}if(this.busy())this.terminating=!0;else{if(this.worker){if("function"==typeof this.worker.kill)this.worker.kill();else{if("function"!=typeof this.worker.terminate)throw new Error("Failed to terminate worker");this.worker.terminate()}this.worker=null}this.terminating=!1,this.terminated=!0}},e.exports=i},function(e,r){e.exports="undefined"!=typeof window?"browser":"node"},function(e,r,t){function n(e){return t(o(e))}function o(e){return i[e]||function(){throw new Error("Cannot find module '"+e+"'.")}()}var i={"./Pool":1,"./Pool.js":1,"./Promise":2,"./Promise.js":2,"./WorkerHandler":3,"./WorkerHandler.js":3,"./environment":4,"./environment.js":4,"./generated/embeddedWorker":6,"./generated/embeddedWorker.js":6,"./header":7,"./header.js":7,"./worker":8,"./worker.js":8};n.keys=function(){return Object.keys(i)},n.resolve=o,e.exports=n,n.id=5},function(e,r){e.exports='!function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(module,exports,__webpack_require__){function isPromise(e){return e&&"function"==typeof e.then&&"function"==typeof e["catch"]}var serializerr=__webpack_require__(1),worker={};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");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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(e){try{var r=worker.methods[e.method];if(!r)throw new Error(\'Unknown method "\'+e.method+\'"\');var t=r.apply(r,e.params);isPromise(t)?t.then(function(r){worker.send({id:e.id,result:r,error:null})})["catch"](function(r){worker.send({id:e.id,result:null,error:serializerr(r)})}):worker.send({id:e.id,result:t,error:null})}catch(n){worker.send({id:e.id,result:null,error:serializerr(n)})}}),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r])},exports.add=worker.register},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=(0,u["default"])(e).filter(function(e){return e!==Object.prototype});return[e].concat(r).map(function(e){return Object.getOwnPropertyNames(e)}).reduce(function(r,t){return t.forEach(function(t){return r[t]=e[t]}),r},{})}Object.defineProperty(r,"__esModule",{value:!0});var s=t(2),u=n(s);e.exports=o,o.serializerr=o,r["default"]=o,e.exports=r["default"]},function(e,r){"use strict";function t(e){for(var r=[],t=n(e);t;)r.push(t),t=n(t);return r}function n(e){return null==e?e:(o(e)&&(e=Object(e)),Object.getPrototypeOf(e))}function o(e){return null===e||"object"!=typeof e&&"function"!=typeof e}e.exports=t}]);'},function(e,r){},function(module,exports,__webpack_require__){function isPromise(e){return e&&"function"==typeof e.then&&"function"==typeof e["catch"]}var serializerr=__webpack_require__(9),worker={};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");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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(e){try{var r=worker.methods[e.method];if(!r)throw new Error('Unknown method "'+e.method+'"');var t=r.apply(r,e.params);isPromise(t)?t.then(function(r){worker.send({id:e.id,result:r,error:null})})["catch"](function(r){worker.send({id:e.id,result:null,error:serializerr(r)})}):worker.send({id:e.id,result:t,error:null})}catch(n){worker.send({id:e.id,result:null,error:serializerr(n)})}}),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r])},exports.add=worker.register},function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=(0,s["default"])(e).filter(function(e){return e!==Object.prototype});return[e].concat(r).map(function(e){return Object.getOwnPropertyNames(e)}).reduce(function(r,t){return t.forEach(function(t){return r[t]=e[t]}),r},{})}Object.defineProperty(r,"__esModule",{value:!0});var i=t(10),s=n(i);e.exports=o,o.serializerr=o,r["default"]=o,e.exports=r["default"]},function(e,r){"use strict";function t(e){for(var r=[],t=n(e);t;)r.push(t),t=n(t);return r}function n(e){return null==e?e:(o(e)&&(e=Object(e)),Object.getPrototypeOf(e))}function o(e){return null===e||"object"!=typeof e&&"function"!=typeof e}e.exports=t}])});
//# sourceMappingURL=workerpool.map

@@ -20,3 +20,3 @@ <!DOCTYPE html>

// offload execution of a function to the worker pool
pool.run(add, [3, 4])
pool.exec(add, [3, 4])
.then(function (result) {

@@ -23,0 +23,0 @@ document.write('Result: ' + result); // outputs 7

@@ -5,2 +5,7 @@ # workerpool history

## 2016-06-25, version 1.2.1
- Fixed #5 error when loading via AMD or bundling using Webpack.
## 2016-05-22, version 1.2.0

@@ -7,0 +12,0 @@

@@ -6,2 +6,2 @@ /**

*/
module.exports = "function isPromise(r){return r&&\"function\"==typeof r.then&&\"function\"==typeof r[\"catch\"]}var serializerr=require(\"serializerr\"),worker={};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\");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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+'\"');var o=e.apply(e,r.params);isPromise(o)?o.then(function(e){worker.send({id:r.id,result:e,error:null})})[\"catch\"](function(e){worker.send({id:r.id,result:null,error:serializerr(e)})}):worker.send({id:r.id,result:o,error:null})}catch(n){worker.send({id:r.id,result:null,error:serializerr(n)})}}),worker.register=function(r){if(r)for(var e in r)r.hasOwnProperty(e)&&(worker.methods[e]=r[e])},\"undefined\"!=typeof exports&&(exports.add=worker.register);";
module.exports = "!function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p=\"\",r(0)}([function(module,exports,__webpack_require__){function isPromise(e){return e&&\"function\"==typeof e.then&&\"function\"==typeof e[\"catch\"]}var serializerr=__webpack_require__(1),worker={};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\");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}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(e){try{var r=worker.methods[e.method];if(!r)throw new Error('Unknown method \"'+e.method+'\"');var t=r.apply(r,e.params);isPromise(t)?t.then(function(r){worker.send({id:e.id,result:r,error:null})})[\"catch\"](function(r){worker.send({id:e.id,result:null,error:serializerr(r)})}):worker.send({id:e.id,result:t,error:null})}catch(n){worker.send({id:e.id,result:null,error:serializerr(n)})}}),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r])},exports.add=worker.register},function(e,r,t){\"use strict\";function n(e){return e&&e.__esModule?e:{\"default\":e}}function o(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=(0,u[\"default\"])(e).filter(function(e){return e!==Object.prototype});return[e].concat(r).map(function(e){return Object.getOwnPropertyNames(e)}).reduce(function(r,t){return t.forEach(function(t){return r[t]=e[t]}),r},{})}Object.defineProperty(r,\"__esModule\",{value:!0});var s=t(2),u=n(s);e.exports=o,o.serializerr=o,r[\"default\"]=o,e.exports=r[\"default\"]},function(e,r){\"use strict\";function t(e){for(var r=[],t=n(e);t;)r.push(t),t=n(t);return r}function n(e){return null==e?e:(o(e)&&(e=Object(e)),Object.getPrototypeOf(e))}function o(e){return null===e||\"object\"!=typeof e&&\"function\"!=typeof e}e.exports=t}]);";

@@ -11,3 +11,3 @@ /**

* @license
* Copyright (C) 2014 Jos de Jong <wjosdejong@gmail.com>
* Copyright (C) 2014-2016 Jos de Jong <wjosdejong@gmail.com>
*

@@ -14,0 +14,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); you may not

var Promise = require('./Promise'),
WorkerHandler = require('./WorkerHandler');
// used to prevent webpack from resolving requires on node libs
var node = {require: require};
/**

@@ -28,3 +31,4 @@ * A pool to manage workers

var environment = require('./environment');
var numCPUs = (environment == 'browser') ? 4 : require('os').cpus().length;
// call node.require to prevent os to be required when loading with AMD
var numCPUs = (environment == 'browser') ? 4 : node.require('os').cpus().length;
this.maxWorkers = Math.max(numCPUs - 1, 1);

@@ -31,0 +35,0 @@ }

@@ -6,3 +6,3 @@ /**

var serializerr = require('serializerr')
var serializerr = require('serializerr');

@@ -9,0 +9,0 @@ // create a worker API for sending and receiving messages which works both on

@@ -6,2 +6,5 @@ var Promise = require('./Promise');

// used to prevent webpack from resolving requires on node libs
var node = {require: require};
// get the default worker script

@@ -75,3 +78,4 @@ function getDefaultWorker() {

// on node.js, create a child process
this.worker = require('child_process').fork(this.script);
// call node.require to prevent child_process to be required when loading with AMD
this.worker = node.require('child_process').fork(this.script);
}

@@ -78,0 +82,0 @@

{
"name": "workerpool",
"version": "1.2.0",
"version": "1.2.1",
"description": "Offload tasks to a pool of workers on node.js and in the browser",

@@ -26,3 +26,2 @@ "homepage": "https://github.com/josdejong/workerpool",

"dependencies": {
"promise": "^5.0.0",
"serializerr": "^1.0.2"

@@ -29,0 +28,0 @@ },

# workerpool
JavaScript is based upon a single event loop which handles one event at a time. Jeremy Epstein [explains this clearly](http://greenash.net.au/thoughts/2012/11/nodejs-itself-is-blocking-only-its-io-is-non-blocking/):
> In Node.js everything runs in parallel, except your code.
> What this means is that all I/O code that you write in Node.js is non-blocking,
> while (conversely) all non-I/O code that you write in Node.js is blocking.
This means that CPU heavy tasks will block other tasks from being executed. In case of a browser environment, the browser will not react to user events like a mouse click while executing a CPU intensive task (the browser "hangs"). In case of a node.js server, the server will not respond to any new request while executing a single, heavy request.
For front-end processes, this is not a desired situation.
Therefore, CPU intensive tasks should be offloaded from the main event loop onto dedicated *workers*. In a browser environment, [Web Workers](http://www.html5rocks.com/en/tutorials/workers/basics/) can be used. In node.js, [child processes](http://nodejs.org/api/child_process.html) are available. An application should be split in separate, decoupled parts, which can run independent of each other in a parallelized way. Effectively, this results in an architecture which achieves concurrency by means of isolated processes and message passing.
**workerpool** offers an easy way to create a pool of workers for both dynamically offloading computations as well as managing a pool of dedicated workers. **workerpool** basically implements a [thread pool pattern](http://en.wikipedia.org/wiki/Thread_pool_pattern). There is a pool of workers to execute tasks. New tasks are put in a queue. A worker executes one task at a time, and once finished, picks a new task from the queue. Workers can be accessed via a natural, promise based proxy, as if they are available straight in the main application.
**workerpool** runs on node.js, Chrome, Firefox, Opera, Safari, and IE10+.
## Features
- Easy to use
- Runs in the browser and on node.js
- Dynamically offload functions to a worker
- Access workers via a proxy
- Cancel running tasks
- Set a timeout on tasks
- Handles crashed workers
- Small, less than 4 kB minified and gzipped
## Install
Install via npm:
npm install workerpool
## Load
To load workerpool in a node.js application (both main application as well as workers):
```js
var workerpool = require('workerpool');
```
To load workerpool in the browser:
```html
<script src="workerpool.js"></script>
```
To load workerpool in a web worker in the browser:
```js
importScripts('workerpool.js');
```
## Use
### Offload functions dynamically
In the following example there is a function `add`, which is offloaded dynamically to a worker to be executed for a given set of arguments.
**myApp.js**
```js
var workerpool = require('workerpool');
var pool = workerpool.pool();
function add(a, b) {
return a + b;
}
pool.exec(add, [3, 4])
.then(function (result) {
console.log('result', result); // outputs 7
pool.clear(); // clear all workers when done
});
```
Note that both function and arguments must be static and stringifiable, as they need to be send to the worker in a serialized form. In case of large functions or function arguments, the overhead of sending the data to the worker can be significant.
### Dedicated workers
A dedicated worker can be created in a separate script, and then used via a worker pool.
**myWorker.js**
```js
var workerpool = require('workerpool');
// a deliberately inefficient implementation of the fibonacci sequence
function fibonacci(n) {
if (n < 2) return n;
return fibonacci(n - 2) + fibonacci(n - 1);
}
// create a worker and register public functions
workerpool.worker({
fibonacci: fibonacci
});
```
This worker can be used by a worker pool:
**myApp.js**
```js
var workerpool = require('workerpool');
// create a worker pool using an external worker script
var pool = workerpool.pool(__dirname + '/myWorker.js');
// run registered functions on the worker via exec
pool.exec('fibonacci', [10])
.then(function (result) {
console.log('Result: ' + result); // outputs 55
pool.clear(); // clear all workers when done
});
// or run registered functions on the worker via a proxy:
pool.proxy()
.then(function (worker) {
worker.fibonacci(10)
.then(function (result) {
console.log('Result: ' + result); // outputs 55
});
});
```
## Examples
Examples are available in the examples directory:
[https://github.com/josdejong/workerpool/tree/master/examples](https://github.com/josdejong/workerpool/tree/master/examples)
## API
The API of workerpool consists of two parts: a function `workerpool.pool` to create a worker pool, and a function `workerpool.worker` to create a worker.
### pool
A workerpool can be created using the function `workerpool.pool`:
`workerpool.pool([script: string] [, options: Object]) : Pool`
When a `script` argument is provided, the provided script will be started as a dedicated worker.
When no `script` argument is provided, a default worker is started which can be used to offload functions dynamically via `Pool.exec`.
Note that on node.js, `script` must be an absolute file path like `__dirname + '/myWorker.js'`.
The following options are available:
- `maxWorkers: number`. The default number of workers on node.js is the number of CPU's minus one. The default number of workers in a browser environment is 3.
A worker pool contains the following functions:
- `Pool.exec(method: Function | string, params: Array | null) : Promise.<*, Error>`<br>
Execute a function on a worker with given arguments.
- When `method` is a string, a method with this name must exist at the worker and must be registered to make it accessible via the pool. The function will be executed on the worker with given parameters.
- When `method` is a function, the provided function `fn` will be stringified, send to the worker, and executed there with the provided parameters. The provided function must be static, it must not depend on variables in a surrounding scope.
- `Pool.proxy() : Promise.<Object, Error>`<br>
Create a proxy for the worker pool. The proxy contains a proxy for all methods available on the worker. All methods return promises resolving the methods result.
- `Pool.clear([force: boolean])`<br>
Clear all workers from the pool. If parameter `force` is false (default), workers will finish the tasks they are working on before terminating themselves. When `force` is true, all workers are terminated immediately without finishing running tasks.
The function `Pool.exec` and the proxy functions all return a `Promise`. The promise has the following functions available:
- `Promise.then(fn: Function.<result: *>)`<br>
Get the result of the promise once resolve.
- `Promise.catch(fn: Function.<error: Error>)`<br>
Get the error of the promise when rejected.
- `Promise.cancel()`<br>
A running task can be cancelled. The worker executing the task is enforced to terminate immediately.
The promise will be rejected with a `Promise.CancellationError`.
- `Promise.timeout(delay: number)`<br>
Cancel a running task when it is not resolved or rejected withing given delay in milliseconds.
The worker executing the task is enforced to terminate immediately.
The promise will be rejected with a `Promise.TimeoutError`.
Example usage:
```js
var workerpool = require('workerpool');
function add(a, b) {
return a + b;
}
var pool1 = workerpool.pool();
// offload a function to a worker
pool1.exec(add, [2, 4])
.then(function (result) {
console.log(result); // will output 6
});
// create a dedicated worker
var pool2 = workerpool.pool(__dirname + '/myWorker.js');
// supposed myWorker.js contains a function 'fibonacci'
pool2.exec('fibonacci', [10])
.then(function (result) {
console.log(result); // will output 55
});
// create a proxy to myWorker.js
pool2.proxy()
.then(function (myWorker) {
myWorker.fibonacci(10)
.then(function (result) {
console.log(result); // will output 55
});
});
// create a pool with a specified maximum number of workers
var pool3 = workerpool.pool({maxWorkers: 7});
```
### worker
A worker is constructed as:
`workerpool.worker([methods: Object.<String, Function>])`
Argument `methods` is optional can can be an object with functions available in the worker. Registered functions will be available via the worker pool.
Example usage:
```js
// file myWorker.js
var workerpool = require('workerpool');
function add(a, b) {
return a + b;
}
function multiply(a, b) {
return a * b;
}
// create a worker and register functions
workerpool.worker({
add: add,
multiply: multiply
});
```
Asynchronous results can be handled by returning a Promise from a function in the worker:
```js
// file myWorker.js
var workerpool = require('workerpool');
function timeout(delay) {
return new Promise(function (resolve, reject) {
setTimeout(resolve, delay)
});
}
// create a worker and register functions
workerpool.worker({
timeout: timeout
});
```
## Roadmap
- Implement a property `minWorkers`, to ensure a minimum number of workers
always up and running.
- Implement functions for parallel processing: `map`, `reduce`, `forEach`,
`filter`, `some`, `every`, ...
- Implement graceful degradation on old browsers not supporting webworkers:
fallback to processing tasks in the main application.
- Implement session support: be able to handle a series of related tasks by a
single worker, which can keep a state for the session.
## Sources of inspiration
- https://github.com/learnboost/cluster
- https://github.com/adambom/parallel.js
- https://github.com/padolsey/operative
- https://github.com/calvinmetcalf/catiline
- https://github.com/Unitech/pm2
- https://github.com/godaddy/node-cluster-service
- https://github.com/ramesaliyev/EasyWebWorker
## Build
First clone the project from github:
git clone git://github.com/josdejong/workerpool.git
cd workerpool
Install the project dependencies:
npm install
Then, the project can be build by executing the build script via npm:
npm run build
This will build the library workerpool.js and workerpool.min.js from the source
files and put them in the folder dist.
## Test
To execute tests for the library, install the project dependencies once:
npm install
Then, the tests can be executed:
npm test
To test code coverage of the tests:
npm run coverage
To see the coverage results, open the generated report in your browser:
./coverage/lcov-report/index.html
## License
Copyright (C) 2014-2016 Jos de Jong <wjosdejong@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.