Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

threads

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

threads - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

.codeclimate.yml

2

bower.json
{
"name": "threads",
"version": "0.5.2",
"version": "0.5.3",
"main": "dist/thread.browser.js",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/andywer/threads.js",

@@ -15,2 +15,6 @@ /*eslint-env worker*/

function handlerProgress(progress) {
this.postMessage({ progress : progress });
}
function handlerDoneTransfer() {

@@ -55,4 +59,4 @@ var args = Array.prototype.slice.call(arguments);

handler.call(this, event.data.param, preparedHandlerDone);
handler.call(this, event.data.param, preparedHandlerDone, handlerProgress.bind(this));
}
}.bind(self);

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

function handlerDone(){var r=Array.prototype.slice.call(arguments,0);this.postMessage({response:r})}function handlerDoneTransfer(){var r=Array.prototype.slice.call(arguments),e=r.pop();e instanceof Array||!this.console||console.error("Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:",e),this.postMessage({response:r},e)}self.module={exports:function(){console&&console.error("No thread logic initialized.")}},self.onmessage=function(r){var e=r.data.scripts;if(e&&e.length>0&&"function"!=typeof importScripts)throw new Error("importScripts() not supported.");if(r.data.initByScripts&&importScripts.apply(null,e),r.data.initByMethod){var t=r.data.method;this.module.exports=Function.apply(null,t.args.concat(t.body)),e&&e.length>0&&importScripts.apply(null,e)}if(r.data.doRun){var o=this.module.exports;if("function"!=typeof o)throw new Error("Cannot run thread logic. No handler has been exported.");var n=handlerDone.bind(this);n.transfer=handlerDoneTransfer.bind(this),o.call(this,r.data.param,n)}}.bind(self);
function handlerDone(){var r=Array.prototype.slice.call(arguments,0);this.postMessage({response:r})}function handlerProgress(r){this.postMessage({progress:r})}function handlerDoneTransfer(){var r=Array.prototype.slice.call(arguments),e=r.pop();e instanceof Array||!this.console||console.error("Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:",e),this.postMessage({response:r},e)}self.module={exports:function(){console&&console.error("No thread logic initialized.")}},self.onmessage=function(r){var e=r.data.scripts;if(e&&e.length>0&&"function"!=typeof importScripts)throw new Error("importScripts() not supported.");if(r.data.initByScripts&&importScripts.apply(null,e),r.data.initByMethod){var t=r.data.method;this.module.exports=Function.apply(null,t.args.concat(t.body)),e&&e.length>0&&importScripts.apply(null,e)}if(r.data.doRun){var o=this.module.exports;if("function"!=typeof o)throw new Error("Cannot run thread logic. No handler has been exported.");var n=handlerDone.bind(this);n.transfer=handlerDoneTransfer.bind(this),o.call(this,r.data.param,n,handlerProgress.bind(this))}}.bind(self);

@@ -190,2 +190,4 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"./defaults":[function(require,module,exports){

this.handleError(event.data.error);
} else if (event.data.progress) {
this.handleProgress(event.data.progress);
} else {

@@ -197,2 +199,6 @@ var responseArgs = convertToArray(event.data.response);

Worker.prototype.handleProgress = function handleProgress(progress) {
this.emit('progress', progress);
};
Worker.prototype.handleError = function handleError(error) {

@@ -565,3 +571,3 @@ if (!this.listeners('error', true)) {

},{"./":3,"./defaults":"./defaults","./job":4,"eventemitter3":7}],6:[function(require,module,exports){
module.exports = "/*eslint-env worker*/\n/*global importScripts*/\n/*eslint-disable no-console*/\nself.module = {\n exports : function() {\n if (console) { console.error('No thread logic initialized.'); }\n }\n};\n\nfunction handlerDone() {\n var args = Array.prototype.slice.call(arguments, 0);\n this.postMessage({ response : args });\n}\n\nfunction handlerDoneTransfer() {\n var args = Array.prototype.slice.call(arguments);\n var lastArg = args.pop();\n\n if (!(lastArg instanceof Array) && this.console) {\n console.error('Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:', lastArg);\n }\n\n this.postMessage({ response : args }, lastArg);\n}\n\nself.onmessage = function (event) {\n var scripts = event.data.scripts;\n if (scripts && scripts.length > 0 && typeof importScripts !== 'function') {\n throw new Error('importScripts() not supported.');\n }\n\n if (event.data.initByScripts) {\n importScripts.apply(null, scripts);\n }\n\n if (event.data.initByMethod) {\n var method = event.data.method;\n this.module.exports = Function.apply(null, method.args.concat(method.body));\n\n if (scripts && scripts.length > 0) {\n importScripts.apply(null, scripts);\n }\n }\n\n if (event.data.doRun) {\n var handler = this.module.exports;\n if (typeof handler !== 'function') {\n throw new Error('Cannot run thread logic. No handler has been exported.');\n }\n\n var preparedHandlerDone = handlerDone.bind(this);\n preparedHandlerDone.transfer = handlerDoneTransfer.bind(this);\n\n handler.call(this, event.data.param, preparedHandlerDone);\n }\n}.bind(self);\n";
module.exports = "/*eslint-env worker*/\n/*global importScripts*/\n/*eslint-disable no-console*/\nself.module = {\n exports : function() {\n if (console) { console.error('No thread logic initialized.'); }\n }\n};\n\nfunction handlerDone() {\n var args = Array.prototype.slice.call(arguments, 0);\n this.postMessage({ response : args });\n}\n\nfunction handlerProgress(progress) {\n this.postMessage({ progress : progress });\n}\n\nfunction handlerDoneTransfer() {\n var args = Array.prototype.slice.call(arguments);\n var lastArg = args.pop();\n\n if (!(lastArg instanceof Array) && this.console) {\n console.error('Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:', lastArg);\n }\n\n this.postMessage({ response : args }, lastArg);\n}\n\nself.onmessage = function (event) {\n var scripts = event.data.scripts;\n if (scripts && scripts.length > 0 && typeof importScripts !== 'function') {\n throw new Error('importScripts() not supported.');\n }\n\n if (event.data.initByScripts) {\n importScripts.apply(null, scripts);\n }\n\n if (event.data.initByMethod) {\n var method = event.data.method;\n this.module.exports = Function.apply(null, method.args.concat(method.body));\n\n if (scripts && scripts.length > 0) {\n importScripts.apply(null, scripts);\n }\n }\n\n if (event.data.doRun) {\n var handler = this.module.exports;\n if (typeof handler !== 'function') {\n throw new Error('Cannot run thread logic. No handler has been exported.');\n }\n\n var preparedHandlerDone = handlerDone.bind(this);\n preparedHandlerDone.transfer = handlerDoneTransfer.bind(this);\n\n handler.call(this, event.data.param, preparedHandlerDone, handlerProgress.bind(this));\n }\n}.bind(self);\n";
},{}],7:[function(require,module,exports){

@@ -568,0 +574,0 @@ 'use strict';

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

require=function t(e,n,r){function o(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return o(n?n:t)},c,c.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({"./defaults":[function(t,e,n){"use strict";n.__esModule=!0,n["default"]={pool:{size:navigator.hardwareConcurrency||8}},e.exports=n["default"]},{}],1:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}var o=t("./index"),i=r(o);"object"==typeof window&&(window.thread=i["default"]),"function"==typeof define?define([],function(){return i["default"]}):"object"==typeof e&&(e.exports=i["default"])},{"./index":3}],"./worker":[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function s(t){var e=p.getConfig().basepath.web;return e?e+"/"+t:t}function a(t){for(var e=[],n=0;"undefined"!=typeof t[n];)e.push(t[n]),n++;return e}function u(t){if(t.stack)console.error(t.stack);else if(t.message&&t.filename&&t.lineno){var e=t.filename.match(/^data:text\/javascript/)&&t.filename.length>50?t.filename.substr(0,50)+"...":t.filename;console.error(t.message+" @"+e+":"+t.lineno)}else console.error(t)}n.__esModule=!0;var f=t("eventemitter3"),c=r(f),l=t("./slave-code"),h=r(l),p=t("../config");if("object"!=typeof window.Worker&&"function"!=typeof window.Worker)throw new Error("Browser does not support web workers!");var d="data:text/javascript;charset=utf-8,"+encodeURI(h["default"]),y=function(t){function e(){var n=arguments.length<=0||void 0===arguments[0]?null:arguments[0],r=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];o(this,e),t.call(this),this.initWorker(),this.worker.addEventListener("message",this.handleMessage.bind(this)),this.worker.addEventListener("error",this.handleError.bind(this)),n&&this.run(n,r)}return i(e,t),e.prototype.initWorker=function(){try{this.worker=new window.Worker(d)}catch(t){var e=p.getConfig().fallback.slaveScriptUrl;if(!e)throw t;this.worker=new window.Worker(d)}},e.prototype.run=function(t){var e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];return"function"==typeof t?this.runMethod(t,e):this.runScripts(t,e),this},e.prototype.runMethod=function(t,e){var n=t.toString(),r=n.substring(n.indexOf("(")+1,n.indexOf(")")).split(","),o=n.substring(n.indexOf("{")+1,n.lastIndexOf("}"));this.worker.postMessage({initByMethod:!0,method:{args:r,body:o},scripts:e.map(s)})},e.prototype.runScripts=function(t,e){if(!t)throw new Error("Must pass a function or a script URL to run().");this.worker.postMessage({initByScripts:!0,scripts:e.concat([t]).map(s)})},e.prototype.send=function(t){var e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];return this.worker.postMessage({doRun:!0,param:t},e),this},e.prototype.kill=function(){return this.worker.terminate(),this.emit("exit"),this},e.prototype.promise=function(){var t=this;return new Promise(function(e,n){t.once("message",e).once("error",n)})},e.prototype.handleMessage=function(t){if(t.data.error)this.handleError(t.data.error);else{var e=a(t.data.response);this.emit.apply(this,["message"].concat(e))}},e.prototype.handleError=function(t){this.listeners("error",!0)||u(t),t.preventDefault&&t.preventDefault(),this.emit("error",t)},e}(c["default"]);n["default"]=y,e.exports=n["default"]},{"../config":2,"./slave-code":6,eventemitter3:7}],2:[function(t,e,n){"use strict";function r(t,e){var n=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];Object.keys(e).forEach(function(o){var i=e[o],s=n.concat([o]);if("object"==typeof i){if("undefined"!=typeof t[o]&&"object"!=typeof t[o])throw new Error("Expected config property not to be an object: "+s.join("."));r(t[o],i,s)}else{if("object"==typeof t[o])throw new Error("Expected config property to be an object: "+s.join("."));t[o]=i}})}function o(){return a.get()}function i(){return a.set.apply(a,arguments)}n.__esModule=!0,n.getConfig=o,n.setConfig=i;var s={basepath:{node:"",web:""},fallback:{slaveScriptUrl:""}},a={get:function(){return s},set:function(t){if("object"!=typeof t)throw new Error("Expected config object.");r(s,t)}};n["default"]=a},{}],3:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0],e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];return new h["default"](t,e)}n.__esModule=!0,n.spawn=o,t("native-promise-only");var i=t("./config"),s=r(i),a=t("./defaults"),u=r(a),f=t("./pool"),c=r(f),l=t("./worker"),h=r(l);n.config=s["default"],n.defaults=u["default"],n.Pool=c["default"],n["default"]={config:s["default"],defaults:u["default"],Pool:c["default"],spawn:o,Worker:h["default"]}},{"./config":2,"./defaults":"./defaults","./pool":5,"./worker":"./worker","native-promise-only":8}],4:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}n.__esModule=!0;var s=t("eventemitter3"),a=r(s),u=function(t){function e(n){o(this,e),t.call(this),this.pool=n,this.thread=null,this.runArgs=[],this.clearSendParameter(),n.emit("newJob",this)}return i(e,t),e.prototype.run=function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(0===e.length)throw new Error("Cannot call .run() without arguments.");return this.runArgs=e,this},e.prototype.send=function(){if(0===this.runArgs.length)throw new Error("Cannot .send() before .run().");for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(this.hasSendParameter()){var r;return(r=this.clone().clearSendParameter()).send.apply(r,e)}return this.sendArgs=e,this.parameterSet=!0,this.emit("readyToRun"),this},e.prototype.executeOn=function(t){var e,n;return(e=(n=t.once("message",this.emit.bind(this,"done")).once("error",this.emit.bind(this,"error"))).run.apply(n,this.runArgs)).send.apply(e,this.sendArgs),this.thread=t,this},e.prototype.promise=function(){if(!this.thread)throw new Error("Cannot return promise, since job is not executed.");return this.thread.promise()},e.prototype.clone=function n(){var n=new e(this.pool);return this.runArgs.length>0&&n.run.apply(n,this.runArgs),this.parameterSet&&n.send.apply(n,this.sendArgs),n},e.prototype.hasSendParameter=function(){return this.parameterSet},e.prototype.clearSendParameter=function(){return this.parameterSet=!1,this.sendArgs=[],this},e}(a["default"]);n["default"]=u,e.exports=n["default"]},{eventemitter3:7}],5:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}n.__esModule=!0;var s=t("eventemitter3"),a=r(s),u=t("./job"),f=r(u),c=t("./defaults"),l=r(c),h=t("./"),p=function(t){function e(n){o(this,e),t.call(this),this.threads=e.spawn(n||l["default"].pool.size),this.idleThreads=this.threads.slice(),this.jobQueue=[],this.lastCreatedJob=null,this.on("newJob",this.handleNewJob.bind(this))}return i(e,t),e.prototype.run=function(){var t;return(t=new f["default"](this)).run.apply(t,arguments)},e.prototype.send=function(){var t;if(!this.lastCreatedJob)throw new Error("Pool.send() called without prior Pool.run(). You need to define what to run first.");return(t=this.lastCreatedJob).send.apply(t,arguments)},e.prototype.killAll=function(){this.threads.forEach(function(t){t.kill()})},e.prototype.queueJob=function(t){this.jobQueue.push(t),this.dequeue()},e.prototype.dequeue=function(){if(0!==this.jobQueue.length&&0!==this.idleThreads.length){var t=this.jobQueue.shift(),e=this.idleThreads.shift();t.on("done",this.handleJobSuccess.bind(this,e,t)).on("error",this.handleJobError.bind(this,e,t)),t.executeOn(e)}},e.prototype.handleNewJob=function(t){this.lastCreatedJob=t,t.on("readyToRun",this.queueJob.bind(this,t))},e.prototype.handleJobSuccess=function(t,e){for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;n>o;o++)r[o-2]=arguments[o];this.emit.apply(this,["done",e].concat(r)),this.handleJobDone(t)},e.prototype.handleJobError=function(t,e,n){this.emit("error",e,n),this.handleJobDone(t)},e.prototype.handleJobDone=function(t){var e=this;this.idleThreads.push(t),this.dequeue(),this.idleThreads.length===this.threads.length&&setTimeout(function(){e.emit("finished")},0)},e}(a["default"]);n["default"]=p,p.spawn=function(t){for(var e=[],n=0;t>n;n++)e.push(h.spawn());return e},e.exports=n["default"]},{"./":3,"./defaults":"./defaults","./job":4,eventemitter3:7}],6:[function(t,e,n){e.exports="/*eslint-env worker*/\n/*global importScripts*/\n/*eslint-disable no-console*/\nself.module = {\n exports : function() {\n if (console) { console.error('No thread logic initialized.'); }\n }\n};\n\nfunction handlerDone() {\n var args = Array.prototype.slice.call(arguments, 0);\n this.postMessage({ response : args });\n}\n\nfunction handlerDoneTransfer() {\n var args = Array.prototype.slice.call(arguments);\n var lastArg = args.pop();\n\n if (!(lastArg instanceof Array) && this.console) {\n console.error('Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:', lastArg);\n }\n\n this.postMessage({ response : args }, lastArg);\n}\n\nself.onmessage = function (event) {\n var scripts = event.data.scripts;\n if (scripts && scripts.length > 0 && typeof importScripts !== 'function') {\n throw new Error('importScripts() not supported.');\n }\n\n if (event.data.initByScripts) {\n importScripts.apply(null, scripts);\n }\n\n if (event.data.initByMethod) {\n var method = event.data.method;\n this.module.exports = Function.apply(null, method.args.concat(method.body));\n\n if (scripts && scripts.length > 0) {\n importScripts.apply(null, scripts);\n }\n }\n\n if (event.data.doRun) {\n var handler = this.module.exports;\n if (typeof handler !== 'function') {\n throw new Error('Cannot run thread logic. No handler has been exported.');\n }\n\n var preparedHandlerDone = handlerDone.bind(this);\n preparedHandlerDone.transfer = handlerDoneTransfer.bind(this);\n\n handler.call(this, event.data.param, preparedHandlerDone);\n }\n}.bind(self);\n"},{}],7:[function(t,e,n){"use strict";function r(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function o(){}var i="function"!=typeof Object.create?"~":!1;o.prototype._events=void 0,o.prototype.listeners=function(t,e){var n=i?i+t:t,r=this._events&&this._events[n];if(e)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,s=r.length,a=new Array(s);s>o;o++)a[o]=r[o].fn;return a},o.prototype.emit=function(t,e,n,r,o,s){var a=i?i+t:t;if(!this._events||!this._events[a])return!1;var u,f,c=this._events[a],l=arguments.length;if("function"==typeof c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,r),!0;case 5:return c.fn.call(c.context,e,n,r,o),!0;case 6:return c.fn.call(c.context,e,n,r,o,s),!0}for(f=1,u=new Array(l-1);l>f;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var h,p=c.length;for(f=0;p>f;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;default:if(!u)for(h=1,u=new Array(l-1);l>h;h++)u[h-1]=arguments[h];c[f].fn.apply(c[f].context,u)}}return!0},o.prototype.on=function(t,e,n){var o=new r(e,n||this),s=i?i+t:t;return this._events||(this._events=i?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],o]:this._events[s].push(o):this._events[s]=o,this},o.prototype.once=function(t,e,n){var o=new r(e,n||this,!0),s=i?i+t:t;return this._events||(this._events=i?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],o]:this._events[s].push(o):this._events[s]=o,this},o.prototype.removeListener=function(t,e,n,r){var o=i?i+t:t;if(!this._events||!this._events[o])return this;var s=this._events[o],a=[];if(e)if(s.fn)(s.fn!==e||r&&!s.once||n&&s.context!==n)&&a.push(s);else for(var u=0,f=s.length;f>u;u++)(s[u].fn!==e||r&&!s[u].once||n&&s[u].context!==n)&&a.push(s[u]);return a.length?this._events[o]=1===a.length?a[0]:a:delete this._events[o],this},o.prototype.removeAllListeners=function(t){return this._events?(t?delete this._events[i?i+t:t]:this._events=i?{}:Object.create(null),this):this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prototype.setMaxListeners=function(){return this},o.prefixed=i,"undefined"!=typeof e&&(e.exports=o)},{}],8:[function(t,e,n){(function(t){!function(t,n,r){n[t]=n[t]||r(),"undefined"!=typeof e&&e.exports?e.exports=n[t]:"function"==typeof define&&define.amd&&define(function(){return n[t]})}("Promise","undefined"!=typeof t?t:this,function(){"use strict";function t(t,e){h.add(t,e),l||(l=d(h.drain))}function e(t){var e,n=typeof t;return null==t||"object"!=n&&"function"!=n||(e=t.then),"function"==typeof e?e:!1}function n(){for(var t=0;t<this.chain.length;t++)r(this,1===this.state?this.chain[t].success:this.chain[t].failure,this.chain[t]);this.chain.length=0}function r(t,n,r){var o,i;try{n===!1?r.reject(t.msg):(o=n===!0?t.msg:n.call(void 0,t.msg),o===r.promise?r.reject(TypeError("Promise-chain cycle")):(i=e(o))?i.call(o,r.resolve,r.reject):r.resolve(o))}catch(s){r.reject(s)}}function o(r){var s,u=this;if(!u.triggered){u.triggered=!0,u.def&&(u=u.def);try{(s=e(r))?t(function(){var t=new a(u);try{s.call(r,function(){o.apply(t,arguments)},function(){i.apply(t,arguments)})}catch(e){i.call(t,e)}}):(u.msg=r,u.state=1,u.chain.length>0&&t(n,u))}catch(f){i.call(new a(u),f)}}}function i(e){var r=this;r.triggered||(r.triggered=!0,r.def&&(r=r.def),r.msg=e,r.state=2,r.chain.length>0&&t(n,r))}function s(t,e,n,r){for(var o=0;o<e.length;o++)!function(o){t.resolve(e[o]).then(function(t){n(o,t)},r)}(o)}function a(t){this.def=t,this.triggered=!1}function u(t){this.promise=t,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function f(e){if("function"!=typeof e)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var r=new u(this);this.then=function(e,o){var i={success:"function"==typeof e?e:!0,failure:"function"==typeof o?o:!1};return i.promise=new this.constructor(function(t,e){if("function"!=typeof t||"function"!=typeof e)throw TypeError("Not a function");i.resolve=t,i.reject=e}),r.chain.push(i),0!==r.state&&t(n,r),i.promise},this["catch"]=function(t){return this.then(void 0,t)};try{e.call(void 0,function(t){o.call(r,t)},function(t){i.call(r,t)})}catch(s){i.call(r,s)}}var c,l,h,p=Object.prototype.toString,d="undefined"!=typeof setImmediate?function(t){return setImmediate(t)}:setTimeout;try{Object.defineProperty({},"x",{}),c=function(t,e,n,r){return Object.defineProperty(t,e,{value:n,writable:!0,configurable:r!==!1})}}catch(y){c=function(t,e,n){return t[e]=n,t}}h=function(){function t(t,e){this.fn=t,this.self=e,this.next=void 0}var e,n,r;return{add:function(o,i){r=new t(o,i),n?n.next=r:e=r,n=r,r=void 0},drain:function(){var t=e;for(e=n=l=void 0;t;)t.fn.call(t.self),t=t.next}}}();var v=c({},"constructor",f,!1);return f.prototype=v,c(v,"__NPO__",0,!1),c(f,"resolve",function(t){var e=this;return t&&"object"==typeof t&&1===t.__NPO__?t:new e(function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");e(t)})}),c(f,"reject",function(t){return new this(function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");n(t)})}),c(f,"all",function(t){var e=this;return"[object Array]"!=p.call(t)?e.reject(TypeError("Not an array")):0===t.length?e.resolve([]):new e(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");var o=t.length,i=Array(o),a=0;s(e,t,function(t,e){i[t]=e,++a===o&&n(i)},r)})}),c(f,"race",function(t){var e=this;return"[object Array]"!=p.call(t)?e.reject(TypeError("Not an array")):new e(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");s(e,t,function(t,e){n(e)},r)})}),f})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]);
require=function t(e,n,r){function o(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return o(n?n:t)},c,c.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({"./defaults":[function(t,e,n){"use strict";n.__esModule=!0,n["default"]={pool:{size:navigator.hardwareConcurrency||8}},e.exports=n["default"]},{}],1:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}var o=t("./index"),i=r(o);"object"==typeof window&&(window.thread=i["default"]),"function"==typeof define?define([],function(){return i["default"]}):"object"==typeof e&&(e.exports=i["default"])},{"./index":3}],"./worker":[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function s(t){var e=p.getConfig().basepath.web;return e?e+"/"+t:t}function a(t){for(var e=[],n=0;"undefined"!=typeof t[n];)e.push(t[n]),n++;return e}function u(t){if(t.stack)console.error(t.stack);else if(t.message&&t.filename&&t.lineno){var e=t.filename.match(/^data:text\/javascript/)&&t.filename.length>50?t.filename.substr(0,50)+"...":t.filename;console.error(t.message+" @"+e+":"+t.lineno)}else console.error(t)}n.__esModule=!0;var f=t("eventemitter3"),c=r(f),l=t("./slave-code"),h=r(l),p=t("../config");if("object"!=typeof window.Worker&&"function"!=typeof window.Worker)throw new Error("Browser does not support web workers!");var d="data:text/javascript;charset=utf-8,"+encodeURI(h["default"]),y=function(t){function e(){var n=arguments.length<=0||void 0===arguments[0]?null:arguments[0],r=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];o(this,e),t.call(this),this.initWorker(),this.worker.addEventListener("message",this.handleMessage.bind(this)),this.worker.addEventListener("error",this.handleError.bind(this)),n&&this.run(n,r)}return i(e,t),e.prototype.initWorker=function(){try{this.worker=new window.Worker(d)}catch(t){var e=p.getConfig().fallback.slaveScriptUrl;if(!e)throw t;this.worker=new window.Worker(d)}},e.prototype.run=function(t){var e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];return"function"==typeof t?this.runMethod(t,e):this.runScripts(t,e),this},e.prototype.runMethod=function(t,e){var n=t.toString(),r=n.substring(n.indexOf("(")+1,n.indexOf(")")).split(","),o=n.substring(n.indexOf("{")+1,n.lastIndexOf("}"));this.worker.postMessage({initByMethod:!0,method:{args:r,body:o},scripts:e.map(s)})},e.prototype.runScripts=function(t,e){if(!t)throw new Error("Must pass a function or a script URL to run().");this.worker.postMessage({initByScripts:!0,scripts:e.concat([t]).map(s)})},e.prototype.send=function(t){var e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];return this.worker.postMessage({doRun:!0,param:t},e),this},e.prototype.kill=function(){return this.worker.terminate(),this.emit("exit"),this},e.prototype.promise=function(){var t=this;return new Promise(function(e,n){t.once("message",e).once("error",n)})},e.prototype.handleMessage=function(t){if(t.data.error)this.handleError(t.data.error);else if(t.data.progress)this.handleProgress(t.data.progress);else{var e=a(t.data.response);this.emit.apply(this,["message"].concat(e))}},e.prototype.handleProgress=function(t){this.emit("progress",t)},e.prototype.handleError=function(t){this.listeners("error",!0)||u(t),t.preventDefault&&t.preventDefault(),this.emit("error",t)},e}(c["default"]);n["default"]=y,e.exports=n["default"]},{"../config":2,"./slave-code":6,eventemitter3:7}],2:[function(t,e,n){"use strict";function r(t,e){var n=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];Object.keys(e).forEach(function(o){var i=e[o],s=n.concat([o]);if("object"==typeof i){if("undefined"!=typeof t[o]&&"object"!=typeof t[o])throw new Error("Expected config property not to be an object: "+s.join("."));r(t[o],i,s)}else{if("object"==typeof t[o])throw new Error("Expected config property to be an object: "+s.join("."));t[o]=i}})}function o(){return a.get()}function i(){return a.set.apply(a,arguments)}n.__esModule=!0,n.getConfig=o,n.setConfig=i;var s={basepath:{node:"",web:""},fallback:{slaveScriptUrl:""}},a={get:function(){return s},set:function(t){if("object"!=typeof t)throw new Error("Expected config object.");r(s,t)}};n["default"]=a},{}],3:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0],e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];return new h["default"](t,e)}n.__esModule=!0,n.spawn=o,t("native-promise-only");var i=t("./config"),s=r(i),a=t("./defaults"),u=r(a),f=t("./pool"),c=r(f),l=t("./worker"),h=r(l);n.config=s["default"],n.defaults=u["default"],n.Pool=c["default"],n["default"]={config:s["default"],defaults:u["default"],Pool:c["default"],spawn:o,Worker:h["default"]}},{"./config":2,"./defaults":"./defaults","./pool":5,"./worker":"./worker","native-promise-only":8}],4:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}n.__esModule=!0;var s=t("eventemitter3"),a=r(s),u=function(t){function e(n){o(this,e),t.call(this),this.pool=n,this.thread=null,this.runArgs=[],this.clearSendParameter(),n.emit("newJob",this)}return i(e,t),e.prototype.run=function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(0===e.length)throw new Error("Cannot call .run() without arguments.");return this.runArgs=e,this},e.prototype.send=function(){if(0===this.runArgs.length)throw new Error("Cannot .send() before .run().");for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];if(this.hasSendParameter()){var r;return(r=this.clone().clearSendParameter()).send.apply(r,e)}return this.sendArgs=e,this.parameterSet=!0,this.emit("readyToRun"),this},e.prototype.executeOn=function(t){var e,n;return(e=(n=t.once("message",this.emit.bind(this,"done")).once("error",this.emit.bind(this,"error"))).run.apply(n,this.runArgs)).send.apply(e,this.sendArgs),this.thread=t,this},e.prototype.promise=function(){if(!this.thread)throw new Error("Cannot return promise, since job is not executed.");return this.thread.promise()},e.prototype.clone=function n(){var n=new e(this.pool);return this.runArgs.length>0&&n.run.apply(n,this.runArgs),this.parameterSet&&n.send.apply(n,this.sendArgs),n},e.prototype.hasSendParameter=function(){return this.parameterSet},e.prototype.clearSendParameter=function(){return this.parameterSet=!1,this.sendArgs=[],this},e}(a["default"]);n["default"]=u,e.exports=n["default"]},{eventemitter3:7}],5:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}n.__esModule=!0;var s=t("eventemitter3"),a=r(s),u=t("./job"),f=r(u),c=t("./defaults"),l=r(c),h=t("./"),p=function(t){function e(n){o(this,e),t.call(this),this.threads=e.spawn(n||l["default"].pool.size),this.idleThreads=this.threads.slice(),this.jobQueue=[],this.lastCreatedJob=null,this.on("newJob",this.handleNewJob.bind(this))}return i(e,t),e.prototype.run=function(){var t;return(t=new f["default"](this)).run.apply(t,arguments)},e.prototype.send=function(){var t;if(!this.lastCreatedJob)throw new Error("Pool.send() called without prior Pool.run(). You need to define what to run first.");return(t=this.lastCreatedJob).send.apply(t,arguments)},e.prototype.killAll=function(){this.threads.forEach(function(t){t.kill()})},e.prototype.queueJob=function(t){this.jobQueue.push(t),this.dequeue()},e.prototype.dequeue=function(){if(0!==this.jobQueue.length&&0!==this.idleThreads.length){var t=this.jobQueue.shift(),e=this.idleThreads.shift();t.on("done",this.handleJobSuccess.bind(this,e,t)).on("error",this.handleJobError.bind(this,e,t)),t.executeOn(e)}},e.prototype.handleNewJob=function(t){this.lastCreatedJob=t,t.on("readyToRun",this.queueJob.bind(this,t))},e.prototype.handleJobSuccess=function(t,e){for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;n>o;o++)r[o-2]=arguments[o];this.emit.apply(this,["done",e].concat(r)),this.handleJobDone(t)},e.prototype.handleJobError=function(t,e,n){this.emit("error",e,n),this.handleJobDone(t)},e.prototype.handleJobDone=function(t){var e=this;this.idleThreads.push(t),this.dequeue(),this.idleThreads.length===this.threads.length&&setTimeout(function(){e.emit("finished")},0)},e}(a["default"]);n["default"]=p,p.spawn=function(t){for(var e=[],n=0;t>n;n++)e.push(h.spawn());return e},e.exports=n["default"]},{"./":3,"./defaults":"./defaults","./job":4,eventemitter3:7}],6:[function(t,e,n){e.exports="/*eslint-env worker*/\n/*global importScripts*/\n/*eslint-disable no-console*/\nself.module = {\n exports : function() {\n if (console) { console.error('No thread logic initialized.'); }\n }\n};\n\nfunction handlerDone() {\n var args = Array.prototype.slice.call(arguments, 0);\n this.postMessage({ response : args });\n}\n\nfunction handlerProgress(progress) {\n this.postMessage({ progress : progress });\n}\n\nfunction handlerDoneTransfer() {\n var args = Array.prototype.slice.call(arguments);\n var lastArg = args.pop();\n\n if (!(lastArg instanceof Array) && this.console) {\n console.error('Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:', lastArg);\n }\n\n this.postMessage({ response : args }, lastArg);\n}\n\nself.onmessage = function (event) {\n var scripts = event.data.scripts;\n if (scripts && scripts.length > 0 && typeof importScripts !== 'function') {\n throw new Error('importScripts() not supported.');\n }\n\n if (event.data.initByScripts) {\n importScripts.apply(null, scripts);\n }\n\n if (event.data.initByMethod) {\n var method = event.data.method;\n this.module.exports = Function.apply(null, method.args.concat(method.body));\n\n if (scripts && scripts.length > 0) {\n importScripts.apply(null, scripts);\n }\n }\n\n if (event.data.doRun) {\n var handler = this.module.exports;\n if (typeof handler !== 'function') {\n throw new Error('Cannot run thread logic. No handler has been exported.');\n }\n\n var preparedHandlerDone = handlerDone.bind(this);\n preparedHandlerDone.transfer = handlerDoneTransfer.bind(this);\n\n handler.call(this, event.data.param, preparedHandlerDone, handlerProgress.bind(this));\n }\n}.bind(self);\n"},{}],7:[function(t,e,n){"use strict";function r(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function o(){}var i="function"!=typeof Object.create?"~":!1;o.prototype._events=void 0,o.prototype.listeners=function(t,e){var n=i?i+t:t,r=this._events&&this._events[n];if(e)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,s=r.length,a=new Array(s);s>o;o++)a[o]=r[o].fn;return a},o.prototype.emit=function(t,e,n,r,o,s){var a=i?i+t:t;if(!this._events||!this._events[a])return!1;var u,f,c=this._events[a],l=arguments.length;if("function"==typeof c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,r),!0;case 5:return c.fn.call(c.context,e,n,r,o),!0;case 6:return c.fn.call(c.context,e,n,r,o,s),!0}for(f=1,u=new Array(l-1);l>f;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var h,p=c.length;for(f=0;p>f;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;default:if(!u)for(h=1,u=new Array(l-1);l>h;h++)u[h-1]=arguments[h];c[f].fn.apply(c[f].context,u)}}return!0},o.prototype.on=function(t,e,n){var o=new r(e,n||this),s=i?i+t:t;return this._events||(this._events=i?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],o]:this._events[s].push(o):this._events[s]=o,this},o.prototype.once=function(t,e,n){var o=new r(e,n||this,!0),s=i?i+t:t;return this._events||(this._events=i?{}:Object.create(null)),this._events[s]?this._events[s].fn?this._events[s]=[this._events[s],o]:this._events[s].push(o):this._events[s]=o,this},o.prototype.removeListener=function(t,e,n,r){var o=i?i+t:t;if(!this._events||!this._events[o])return this;var s=this._events[o],a=[];if(e)if(s.fn)(s.fn!==e||r&&!s.once||n&&s.context!==n)&&a.push(s);else for(var u=0,f=s.length;f>u;u++)(s[u].fn!==e||r&&!s[u].once||n&&s[u].context!==n)&&a.push(s[u]);return a.length?this._events[o]=1===a.length?a[0]:a:delete this._events[o],this},o.prototype.removeAllListeners=function(t){return this._events?(t?delete this._events[i?i+t:t]:this._events=i?{}:Object.create(null),this):this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prototype.setMaxListeners=function(){return this},o.prefixed=i,"undefined"!=typeof e&&(e.exports=o)},{}],8:[function(t,e,n){(function(t){!function(t,n,r){n[t]=n[t]||r(),"undefined"!=typeof e&&e.exports?e.exports=n[t]:"function"==typeof define&&define.amd&&define(function(){return n[t]})}("Promise","undefined"!=typeof t?t:this,function(){"use strict";function t(t,e){h.add(t,e),l||(l=d(h.drain))}function e(t){var e,n=typeof t;return null==t||"object"!=n&&"function"!=n||(e=t.then),"function"==typeof e?e:!1}function n(){for(var t=0;t<this.chain.length;t++)r(this,1===this.state?this.chain[t].success:this.chain[t].failure,this.chain[t]);this.chain.length=0}function r(t,n,r){var o,i;try{n===!1?r.reject(t.msg):(o=n===!0?t.msg:n.call(void 0,t.msg),o===r.promise?r.reject(TypeError("Promise-chain cycle")):(i=e(o))?i.call(o,r.resolve,r.reject):r.resolve(o))}catch(s){r.reject(s)}}function o(r){var s,u=this;if(!u.triggered){u.triggered=!0,u.def&&(u=u.def);try{(s=e(r))?t(function(){var t=new a(u);try{s.call(r,function(){o.apply(t,arguments)},function(){i.apply(t,arguments)})}catch(e){i.call(t,e)}}):(u.msg=r,u.state=1,u.chain.length>0&&t(n,u))}catch(f){i.call(new a(u),f)}}}function i(e){var r=this;r.triggered||(r.triggered=!0,r.def&&(r=r.def),r.msg=e,r.state=2,r.chain.length>0&&t(n,r))}function s(t,e,n,r){for(var o=0;o<e.length;o++)!function(o){t.resolve(e[o]).then(function(t){n(o,t)},r)}(o)}function a(t){this.def=t,this.triggered=!1}function u(t){this.promise=t,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function f(e){if("function"!=typeof e)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var r=new u(this);this.then=function(e,o){var i={success:"function"==typeof e?e:!0,failure:"function"==typeof o?o:!1};return i.promise=new this.constructor(function(t,e){if("function"!=typeof t||"function"!=typeof e)throw TypeError("Not a function");i.resolve=t,i.reject=e}),r.chain.push(i),0!==r.state&&t(n,r),i.promise},this["catch"]=function(t){return this.then(void 0,t)};try{e.call(void 0,function(t){o.call(r,t)},function(t){i.call(r,t)})}catch(s){i.call(r,s)}}var c,l,h,p=Object.prototype.toString,d="undefined"!=typeof setImmediate?function(t){return setImmediate(t)}:setTimeout;try{Object.defineProperty({},"x",{}),c=function(t,e,n,r){return Object.defineProperty(t,e,{value:n,writable:!0,configurable:r!==!1})}}catch(y){c=function(t,e,n){return t[e]=n,t}}h=function(){function t(t,e){this.fn=t,this.self=e,this.next=void 0}var e,n,r;return{add:function(o,i){r=new t(o,i),n?n.next=r:e=r,n=r,r=void 0},drain:function(){var t=e;for(e=n=l=void 0;t;)t.fn.call(t.self),t=t.next}}}();var g=c({},"constructor",f,!1);return f.prototype=g,c(g,"__NPO__",0,!1),c(f,"resolve",function(t){var e=this;return t&&"object"==typeof t&&1===t.__NPO__?t:new e(function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");e(t)})}),c(f,"reject",function(t){return new this(function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");n(t)})}),c(f,"all",function(t){var e=this;return"[object Array]"!=p.call(t)?e.reject(TypeError("Not an array")):0===t.length?e.resolve([]):new e(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");var o=t.length,i=Array(o),a=0;s(e,t,function(t,e){i[t]=e,++a===o&&n(i)},r)})}),c(f,"race",function(t){var e=this;return"[object Array]"!=p.call(t)?e.reject(TypeError("Not an array")):new e(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");s(e,t,function(t,e){n(e)},r)})}),f})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]);

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

module.exports = "/*eslint-env worker*/\n/*global importScripts*/\n/*eslint-disable no-console*/\nself.module = {\n exports : function() {\n if (console) { console.error('No thread logic initialized.'); }\n }\n};\n\nfunction handlerDone() {\n var args = Array.prototype.slice.call(arguments, 0);\n this.postMessage({ response : args });\n}\n\nfunction handlerDoneTransfer() {\n var args = Array.prototype.slice.call(arguments);\n var lastArg = args.pop();\n\n if (!(lastArg instanceof Array) && this.console) {\n console.error('Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:', lastArg);\n }\n\n this.postMessage({ response : args }, lastArg);\n}\n\nself.onmessage = function (event) {\n var scripts = event.data.scripts;\n if (scripts && scripts.length > 0 && typeof importScripts !== 'function') {\n throw new Error('importScripts() not supported.');\n }\n\n if (event.data.initByScripts) {\n importScripts.apply(null, scripts);\n }\n\n if (event.data.initByMethod) {\n var method = event.data.method;\n this.module.exports = Function.apply(null, method.args.concat(method.body));\n\n if (scripts && scripts.length > 0) {\n importScripts.apply(null, scripts);\n }\n }\n\n if (event.data.doRun) {\n var handler = this.module.exports;\n if (typeof handler !== 'function') {\n throw new Error('Cannot run thread logic. No handler has been exported.');\n }\n\n var preparedHandlerDone = handlerDone.bind(this);\n preparedHandlerDone.transfer = handlerDoneTransfer.bind(this);\n\n handler.call(this, event.data.param, preparedHandlerDone);\n }\n}.bind(self);\n";
module.exports = "/*eslint-env worker*/\n/*global importScripts*/\n/*eslint-disable no-console*/\nself.module = {\n exports : function() {\n if (console) { console.error('No thread logic initialized.'); }\n }\n};\n\nfunction handlerDone() {\n var args = Array.prototype.slice.call(arguments, 0);\n this.postMessage({ response : args });\n}\n\nfunction handlerProgress(progress) {\n this.postMessage({ progress : progress });\n}\n\nfunction handlerDoneTransfer() {\n var args = Array.prototype.slice.call(arguments);\n var lastArg = args.pop();\n\n if (!(lastArg instanceof Array) && this.console) {\n console.error('Expected 2nd parameter of <doneCallback>.transfer() to be an array. Got:', lastArg);\n }\n\n this.postMessage({ response : args }, lastArg);\n}\n\nself.onmessage = function (event) {\n var scripts = event.data.scripts;\n if (scripts && scripts.length > 0 && typeof importScripts !== 'function') {\n throw new Error('importScripts() not supported.');\n }\n\n if (event.data.initByScripts) {\n importScripts.apply(null, scripts);\n }\n\n if (event.data.initByMethod) {\n var method = event.data.method;\n this.module.exports = Function.apply(null, method.args.concat(method.body));\n\n if (scripts && scripts.length > 0) {\n importScripts.apply(null, scripts);\n }\n }\n\n if (event.data.doRun) {\n var handler = this.module.exports;\n if (typeof handler !== 'function') {\n throw new Error('Cannot run thread logic. No handler has been exported.');\n }\n\n var preparedHandlerDone = handlerDone.bind(this);\n preparedHandlerDone.transfer = handlerDoneTransfer.bind(this);\n\n handler.call(this, event.data.param, preparedHandlerDone, handlerProgress.bind(this));\n }\n}.bind(self);\n";

@@ -152,2 +152,4 @@ 'use strict';

this.handleError(event.data.error);
} else if (event.data.progress) {
this.handleProgress(event.data.progress);
} else {

@@ -159,2 +161,6 @@ var responseArgs = convertToArray(event.data.response);

Worker.prototype.handleProgress = function handleProgress(progress) {
this.emit('progress', progress);
};
Worker.prototype.handleError = function handleError(error) {

@@ -161,0 +167,0 @@ if (!this.listeners('error', true)) {

@@ -59,2 +59,6 @@ // not using ES6 import/export syntax, since we need to require() in a handler

function messageHandlerProgress(progress) {
process.send({ progress: progress });
}
process.on('message', function (data) {

@@ -74,5 +78,5 @@ if (data.initByScript) {

messageHandler(data.param, messageHandlerDone);
messageHandler(data.param, messageHandlerDone, messageHandlerProgress);
}
});
//# sourceMappingURL=../worker.node/slave.js.map

@@ -102,2 +102,4 @@ 'use strict';

this.handleError(error);
} else if (message.progress) {
this.handleProgress(message.progress);
} else {

@@ -108,2 +110,6 @@ this.emit.apply(this, ['message'].concat(message.response));

Worker.prototype.handleProgress = function handleProgress(progress) {
this.emit('progress', progress);
};
Worker.prototype.handleError = function handleError(error) {

@@ -110,0 +116,0 @@ if (!this.listeners('error', true)) {

{
"name": "threads",
"version": "0.5.2",
"version": "0.5.3",
"keywords": [

@@ -32,2 +32,4 @@ "threads",

"browserify": "^9.0.8",
"codeclimate-test-reporter": "^0.1.1",
"coveralls": "^2.11.4",
"expect.js": "^0.3.1",

@@ -42,2 +44,3 @@ "gulp": "^3.8.11",

"gulp-uglify": "^1.2.0",
"istanbul": "^0.4.0",
"karma": "^0.13.9",

@@ -44,0 +47,0 @@ "karma-browserify": "^4.3.0",

# threads.js
[![Build Status](https://travis-ci.org/andywer/threads.js.svg?branch=master)](https://travis-ci.org/andywer/threads.js)
[![Test Coverage](https://codeclimate.com/github/andywer/threads.js/badges/coverage.svg)](https://codeclimate.com/github/andywer/threads.js/coverage)
[![Code Climate](https://codeclimate.com/github/andywer/threads.js/badges/gpa.svg)](https://codeclimate.com/github/andywer/threads.js)
[![NPM Version](https://img.shields.io/npm/v/threads.svg)](https://www.npmjs.com/package/threads)

@@ -68,3 +70,3 @@

(where `__VERSION__` is the library's version to use, like `0.5.0`)
(where `__VERSION__` is the library's version to use, like `0.5.3`)

@@ -115,2 +117,4 @@

to the thread pool which it will queue and pass to the next idle worker.
You can also pass the number threads to be spawned. Defaults to the number of
CPU cores.

@@ -122,2 +126,3 @@ ```javascript

const pool = new Pool();
// Alternatively: new Pool(<number of threads to spawn>)

@@ -232,3 +237,2 @@ // Run a script

### Transferable objects

@@ -262,2 +266,32 @@

### Progress update
The thread can also notify the main thread about its current progress.
```javascript
thread
.run(function(input, done, progress) {
setTimeout(done, 1000);
setTimeout(function() { progress(25); }, 250);
setTimeout(function() { progress(50); }, 500);
setTimeout(function() { progress(75); }, 750);
})
.send()
.on('progress', function(progress) {
console.log(`Progress: ${progress}%`);
})
.on('done', function() {
console.log(`Done.`);
});
```
Output:
```
Progress: 25%
Progress: 50%
Progress: 75%
Done.
```
### Web worker fallback

@@ -268,3 +302,2 @@

### Use external dependencies

@@ -271,0 +304,0 @@

@@ -15,2 +15,6 @@ /*eslint-env worker*/

function handlerProgress(progress) {
this.postMessage({ progress : progress });
}
function handlerDoneTransfer() {

@@ -55,4 +59,4 @@ var args = Array.prototype.slice.call(arguments);

handler.call(this, event.data.param, preparedHandlerDone);
handler.call(this, event.data.param, preparedHandlerDone, handlerProgress.bind(this));
}
}.bind(self);

@@ -129,2 +129,4 @@ import EventEmitter from 'eventemitter3';

this.handleError(event.data.error);
} else if (event.data.progress) {
this.handleProgress(event.data.progress);
} else {

@@ -136,2 +138,6 @@ const responseArgs = convertToArray(event.data.response);

handleProgress(progress) {
this.emit('progress', progress);
}
handleError(error) {

@@ -138,0 +144,0 @@ if (!this.listeners('error', true)) {

@@ -49,3 +49,7 @@ // not using ES6 import/export syntax, since we need to require() in a handler

function messageHandlerProgress(progress) {
process.send({ progress });
}
process.on('message', function(data) {

@@ -65,4 +69,4 @@ if (data.initByScript) {

messageHandler(data.param, messageHandlerDone);
messageHandler(data.param, messageHandlerDone, messageHandlerProgress);
}
});

@@ -77,2 +77,4 @@ import child from 'child_process';

this.handleError(error);
} else if (message.progress) {
this.handleProgress(message.progress);
} else {

@@ -83,2 +85,6 @@ this.emit('message', ...message.response);

handleProgress(progress) {
this.emit('progress', progress);
}
handleError(error) {

@@ -85,0 +91,0 @@ if (!this.listeners('error', true)) {

@@ -14,2 +14,8 @@ import async from 'async';

function progressThread(param, done, progress) {
progress(0.3);
progress(0.6);
done();
}
function canSendAndReceive(worker, dataToSend, expectToRecv, done) {

@@ -166,3 +172,18 @@ worker

it('can update progress', done => {
const progressUpdates = [];
const worker = spawn(progressThread);
worker.on('progress', progress => {
progressUpdates.push(progress);
});
worker.send();
worker.on('message', () => {
expect(progressUpdates).to.eql([ 0.3, 0.6 ]);
done();
});
});
if (env === 'node') {

@@ -169,0 +190,0 @@

@@ -29,2 +29,8 @@ 'use strict';

function progressThread(param, done, progress) {
progress(0.3);
progress(0.6);
done();
}
function canSendAndReceive(worker, dataToSend, expectToRecv, done) {

@@ -167,2 +173,17 @@ worker.once('message', function (data) {

it('can update progress', function (done) {
var progressUpdates = [];
var worker = (0, _.spawn)(progressThread);
worker.on('progress', function (progress) {
progressUpdates.push(progress);
});
worker.send();
worker.on('message', function () {
(0, _expectJs2['default'])(progressUpdates).to.eql([0.3, 0.6]);
done();
});
});
if (env === 'node') {

@@ -169,0 +190,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc