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.7.2 to 0.7.3

.doclets.yml

4

bower.json
{
"name": "threads",
"version": "0.6.1",
"main": "dist/thread.browser.js",
"version": "0.7.3",
"main": "dist/threads.browser.js",
"homepage": "https://github.com/andywer/threads.js",

@@ -6,0 +6,0 @@ "authors": [

# threads.js - Changelog
## Upcoming release
## 0.7.3
- Trigger worker error event on unhandled promise rejection in worker [#49](https://github.com/andywer/threads.js/issues/49)
- Merged lost commits stuck in the `develop` branch [#51](https://github.com/andywer/threads.js/pull/51)
## 0.7.2
- Fixes another memory leak. Credit goes to https://github.com/ChiperSoft

@@ -6,0 +11,0 @@ - Depedencies have been updated. threads.js will cannot be built and tested anymore on node 0.12. Node >= 4.0 is from now on required. The lib will still work on Node 0.12, though.

@@ -113,3 +113,3 @@ 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){

// try using the slave script file instead of the data URI
this.worker = new window.Worker(_slaveCodeUri2.default);
this.worker = new window.Worker(slaveScriptUrl);
} else {

@@ -446,3 +446,2 @@ // re-throw

this.thread = thread;
this.emit('threadChanged');

@@ -468,2 +467,8 @@ return this;

Job.prototype.destroy = function destroy() {
this.removeAllListeners();
delete this.runArgs;
delete this.sendArgs;
};
return Job;

@@ -534,2 +539,4 @@ }(_eventemitter2.default);

Pool.prototype.send = function send() {
var _job$run;
if (!this.runArgs) {

@@ -540,4 +547,3 @@ throw new Error('Pool.send() called without prior Pool.run(). You need to define what to run first.');

var job = new _job2.default(this);
job.run.apply(job, this.runArgs);
return job.send.apply(job, arguments);
return (_job$run = job.run.apply(job, this.runArgs)).send.apply(_job$run, arguments);
};

@@ -586,3 +592,2 @@

this.lastCreatedJob = job;
job.once('readyToRun', function () {

@@ -599,3 +604,3 @@ return _this3.queueJob(job);

this.emit.apply(this, ['done', job].concat(responseArgs));
this.handleJobDone(thread);
this.handleJobDone(thread, job);
};

@@ -605,8 +610,9 @@

this.emit('error', job, error);
this.handleJobDone(thread);
this.handleJobDone(thread, job);
};
Pool.prototype.handleJobDone = function handleJobDone(thread) {
Pool.prototype.handleJobDone = function handleJobDone(thread, job) {
var _this4 = this;
job.destroy(); // to prevent memory leak
this.idleThreads.push(thread);

@@ -613,0 +619,0 @@ this.emit('threadAvailable');

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

require=function e(t,n,r){function o(s,a){if(!n[s]){if(!t[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:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return o(n?n:e)},c,c.exports,e,t,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(e,t,n){"use strict";n.__esModule=!0,n.default={pool:{size:navigator.hardwareConcurrency||8}}},{}],"./worker":[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t){return e&&t?"/"===e.charAt(e.length-1)||"/"===t.charAt(0)?e+t:e+"/"+t:e+t}function u(e){var t=(0,v.getConfig)().basepath.web;return t?a(t,e):e}function f(e){for(var t=[],n=0;"undefined"!=typeof e[n];)t.push(e[n]),n++;return t}function c(e){if(e.stack)console.error(e.stack);else if(e.message&&e.filename&&e.lineno){var t=e.filename.match(/^data:text\/javascript/)&&e.filename.length>50?e.filename.substr(0,50)+"...":e.filename;console.error(e.message+" @"+t+":"+e.lineno)}else console.error(e)}n.__esModule=!0;var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p=e("eventemitter3"),h=r(p),d=e("./slave-code-uri"),y=r(d),v=e("../config");if("object"!==l(window.Worker)&&"function"!=typeof window.Worker)throw new Error("Browser does not support web workers!");var w=function(e){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];o(this,t);var s=i(this,e.call(this));return s.currentRunnable=null,s.currentImportScripts=[],s.initWorker(),s.worker.addEventListener("message",s.handleMessage.bind(s)),s.worker.addEventListener("error",s.handleError.bind(s)),n&&s.run(n,r),s}return s(t,e),t.prototype.initWorker=function(){try{this.worker=new window.Worker(y.default)}catch(t){var e=(0,v.getConfig)().fallback.slaveScriptUrl;if(!e)throw t;this.worker=new window.Worker(y.default)}},t.prototype.run=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return this.alreadyInitializedToRun(e,t)?this:("function"==typeof e?this.runMethod(e,t):this.runScripts(e,t),this.currentRunnable=e,this.currentImportScripts=t,this)},t.prototype.runMethod=function(e,t){var n=e.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:t.map(u)})},t.prototype.runScripts=function(e,t){if(!e)throw new Error("Must pass a function or a script URL to run().");this.worker.postMessage({initByScripts:!0,scripts:t.concat([e]).map(u)})},t.prototype.send=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return this.worker.postMessage({doRun:!0,param:e},t),this},t.prototype.kill=function(){return this.worker.terminate(),this.emit("exit"),this},t.prototype.promise=function(){var e=this;return new Promise(function(t,n){var r=void 0,o=void 0;r=function(n){e.removeListener("error",o),t(n)},o=function(t){e.removeListener("message",r),n(t)},e.once("message",r).once("error",o)})},t.prototype.alreadyInitializedToRun=function(e,t){var n=this.currentRunnable===e,r=this.currentImportScripts===t||0===t.length&&0===this.currentImportScripts.length;return n&&r},t.prototype.handleMessage=function(e){if(e.data.error)this.handleError(e.data.error);else if(e.data.progress)this.handleProgress(e.data.progress);else{var t=f(e.data.response);this.emit.apply(this,["message"].concat(t)),this.emit.apply(this,["done"].concat(t))}},t.prototype.handleProgress=function(e){this.emit("progress",e)},t.prototype.handleError=function(e){this.listeners("error",!0)||c(e),e.preventDefault&&e.preventDefault(),this.emit("error",e)},t}(h.default);n.default=w},{"../config":2,"./slave-code-uri":6,eventemitter3:8}],1:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=e("./index"),s=r(i);"object"===("undefined"==typeof window?"undefined":o(window))&&(window.thread=s.default),"function"==typeof define?define([],function(){return s.default}):"object"===("undefined"==typeof t?"undefined":o(t))&&(t.exports=s.default)},{"./index":3}],2:[function(e,t,n){"use strict";function r(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];Object.keys(t).forEach(function(o){var i=t[o],a=n.concat([o]);if("object"===("undefined"==typeof i?"undefined":s(i))){if("undefined"!=typeof e[o]&&"object"!==s(e[o]))throw new Error("Expected config property not to be an object: "+a.join("."));r(e[o],i,a)}else{if("object"===s(e[o]))throw new Error("Expected config property to be an object: "+a.join("."));e[o]=i}})}function o(){return u.get()}function i(){return u.set.apply(u,arguments)}n.__esModule=!0;var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};n.getConfig=o,n.setConfig=i;var a={basepath:{node:"",web:""},fallback:{slaveScriptUrl:""}},u={get:function(){return a},set:function(e){if("object"!==("undefined"==typeof e?"undefined":s(e)))throw new Error("Expected config object.");r(a,e)}};n.default=u},{}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return new p.default(e,t)}n.__esModule=!0,n.Pool=n.defaults=n.config=void 0,n.spawn=o,e("native-promise-only");var i=e("./config"),s=r(i),a=e("./defaults"),u=r(a),f=e("./pool"),c=r(f),l=e("./worker"),p=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:p.default}},{"./config":2,"./defaults":"./defaults","./pool":5,"./worker":"./worker","native-promise-only":9}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}n.__esModule=!0;var a=e("eventemitter3"),u=r(a),f=function(e){function t(n){o(this,t);var r=i(this,e.call(this));return r.pool=n,r.thread=null,r.runArgs=[],r.sendArgs=[],n.emit("newJob",r),r}return s(t,e),t.prototype.run=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];if(0===t.length)throw new Error("Cannot call .run() without arguments.");return this.runArgs=t,this},t.prototype.send=function(){if(0===this.runArgs.length)throw new Error("Cannot .send() before .run().");for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.sendArgs=t,this.emit("readyToRun"),this},t.prototype.executeOn=function(e){var t,n;return(t=(n=e.once("message",this.emit.bind(this,"done")).once("error",this.emit.bind(this,"error"))).run.apply(n,this.runArgs)).send.apply(t,this.sendArgs),this.thread=e,this.emit("threadChanged"),this},t.prototype.promise=function(){var e=this;return new Promise(function(t){e.thread?t(e.thread.promise()):e.once("threadChanged",function(){t(e.thread.promise())})})},t}(u.default);n.default=f},{eventemitter3:8}],5:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}n.__esModule=!0;var a=e("eventemitter3"),u=r(a),f=e("./job"),c=r(f),l=e("./defaults"),p=r(l),h=e("./"),d=function(e){function t(n){o(this,t);var r=i(this,e.call(this));return r.threads=t.spawn(n||p.default.pool.size),r.idleThreads=r.threads.slice(),r.jobQueue=[],r.runArgs=[],r.on("newJob",function(e){return r.handleNewJob(e)}),r.on("threadAvailable",function(){return r.dequeue()}),r}return s(t,e),t.prototype.run=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.runArgs=t,this},t.prototype.send=function(){if(!this.runArgs)throw new Error("Pool.send() called without prior Pool.run(). You need to define what to run first.");var e=new c.default(this);return e.run.apply(e,this.runArgs),e.send.apply(e,arguments)},t.prototype.killAll=function(){this.threads.forEach(function(e){e.kill()})},t.prototype.queueJob=function(e){this.jobQueue.push(e),this.dequeue()},t.prototype.dequeue=function(){var e=this;if(0!==this.jobQueue.length&&0!==this.idleThreads.length){var t=this.jobQueue.shift(),n=this.idleThreads.shift();t.once("done",function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e.handleJobSuccess.apply(e,[n,t].concat(o))}).once("error",function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e.handleJobError.apply(e,[n,t].concat(o))}),t.executeOn(n)}},t.prototype.handleNewJob=function(e){var t=this;this.lastCreatedJob=e,e.once("readyToRun",function(){return t.queueJob(e)})},t.prototype.handleJobSuccess=function(e,t){for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];this.emit.apply(this,["done",t].concat(r)),this.handleJobDone(e)},t.prototype.handleJobError=function(e,t,n){this.emit("error",t,n),this.handleJobDone(e)},t.prototype.handleJobDone=function(e){var t=this;this.idleThreads.push(e),this.emit("threadAvailable"),this.idleThreads.length===this.threads.length&&setTimeout(function(){t.emit("finished")},0)},t}(u.default);n.default=d,d.spawn=function(e){for(var t=[],n=0;n<e;n++)t.push((0,h.spawn)());return t}},{"./":3,"./defaults":"./defaults","./job":4,eventemitter3:8}],6:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}n.__esModule=!0;var o=e("./slave-code"),i=r(o),s="data:text/javascript;charset=utf-8,"+encodeURI(i.default),a=window.createBlobURL||window.createObjectURL;if(!a){var u=window.URL||window.webkitURL;if(!u)throw new Error("No Blob creation implementation found.");a=u.createObjectURL}if("function"==typeof window.BlobBuilder&&"function"==typeof a){var f=new window.BlobBuilder;f.append(i.default),s=a(f.getBlob())}else if("function"==typeof window.Blob&&"function"==typeof a){var c=new window.Blob([i.default],{type:"text/javascript"});s=a(c)}n.default=s},{"./slave-code":7}],7:[function(e,t,n){t.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"},{}],8:[function(e,t,n){"use strict";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(){this._events=new r,this._eventsCount=0}var s=Object.prototype.hasOwnProperty,a="~";Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(a=!1)),i.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)s.call(e,t)&&n.push(a?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},i.prototype.listeners=function(e,t){var n=a?a+e:e,r=this._events[n];if(t)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,i=r.length,s=new Array(i);o<i;o++)s[o]=r[o].fn;return s},i.prototype.emit=function(e,t,n,r,o,i){var s=a?a+e:e;if(!this._events[s])return!1;var u,f,c=this._events[s],l=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,r),!0;case 5:return c.fn.call(c.context,t,n,r,o),!0;case 6:return c.fn.call(c.context,t,n,r,o,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var p,h=c.length;for(f=0;f<h;f++)switch(c[f].once&&this.removeListener(e,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,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,r);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[f].fn.apply(c[f].context,u)}}return!0},i.prototype.on=function(e,t,n){var r=new o(t,n||this),i=a?a+e:e;return this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],r]:this._events[i].push(r):(this._events[i]=r,this._eventsCount++),this},i.prototype.once=function(e,t,n){var r=new o(t,n||this,(!0)),i=a?a+e:e;return this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],r]:this._events[i].push(r):(this._events[i]=r,this._eventsCount++),this},i.prototype.removeListener=function(e,t,n,o){var i=a?a+e:e;if(!this._events[i])return this;if(!t)return 0===--this._eventsCount?this._events=new r:delete this._events[i],this;var s=this._events[i];if(s.fn)s.fn!==t||o&&!s.once||n&&s.context!==n||(0===--this._eventsCount?this._events=new r:delete this._events[i]);else{for(var u=0,f=[],c=s.length;u<c;u++)(s[u].fn!==t||o&&!s[u].once||n&&s[u].context!==n)&&f.push(s[u]);f.length?this._events[i]=1===f.length?f[0]:f:0===--this._eventsCount?this._events=new r:delete this._events[i]}return this},i.prototype.removeAllListeners=function(e){var t;return e?(t=a?a+e:e,this._events[t]&&(0===--this._eventsCount?this._events=new r:delete this._events[t])):(this._events=new r,this._eventsCount=0),this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prototype.setMaxListeners=function(){return this},i.prefixed=a,i.EventEmitter=i,"undefined"!=typeof t&&(t.exports=i)},{}],9:[function(e,t,n){(function(e){!function(e,n,r){n[e]=n[e]||r(),"undefined"!=typeof t&&t.exports?t.exports=n[e]:"function"==typeof define&&define.amd&&define(function(){return n[e]})}("Promise","undefined"!=typeof e?e:this,function(){"use strict";function e(e,t){p.add(e,t),l||(l=d(p.drain))}function t(e){var t,n=typeof e;return null==e||"object"!=n&&"function"!=n||(t=e.then),"function"==typeof t&&t}function n(){for(var e=0;e<this.chain.length;e++)r(this,1===this.state?this.chain[e].success:this.chain[e].failure,this.chain[e]);this.chain.length=0}function r(e,n,r){var o,i;try{n===!1?r.reject(e.msg):(o=n===!0?e.msg:n.call(void 0,e.msg),o===r.promise?r.reject(TypeError("Promise-chain cycle")):(i=t(o))?i.call(o,r.resolve,r.reject):r.resolve(o))}catch(e){r.reject(e)}}function o(r){var s,u=this;if(!u.triggered){u.triggered=!0,u.def&&(u=u.def);try{(s=t(r))?e(function(){var e=new a(u);try{s.call(r,function(){o.apply(e,arguments)},function(){i.apply(e,arguments)})}catch(t){i.call(e,t)}}):(u.msg=r,u.state=1,u.chain.length>0&&e(n,u))}catch(e){i.call(new a(u),e)}}}function i(t){var r=this;r.triggered||(r.triggered=!0,r.def&&(r=r.def),r.msg=t,r.state=2,r.chain.length>0&&e(n,r))}function s(e,t,n,r){for(var o=0;o<t.length;o++)!function(o){e.resolve(t[o]).then(function(e){n(o,e)},r)}(o)}function a(e){this.def=e,this.triggered=!1}function u(e){this.promise=e,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function f(t){if("function"!=typeof t)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(t,o){var i={success:"function"!=typeof t||t,failure:"function"==typeof o&&o};return i.promise=new this.constructor(function(e,t){if("function"!=typeof e||"function"!=typeof t)throw TypeError("Not a function");i.resolve=e,i.reject=t}),r.chain.push(i),0!==r.state&&e(n,r),i.promise},this.catch=function(e){return this.then(void 0,e)};try{t.call(void 0,function(e){o.call(r,e)},function(e){i.call(r,e)})}catch(e){i.call(r,e)}}var c,l,p,h=Object.prototype.toString,d="undefined"!=typeof setImmediate?function(e){return setImmediate(e)}:setTimeout;try{Object.defineProperty({},"x",{}),c=function(e,t,n,r){return Object.defineProperty(e,t,{value:n,writable:!0,configurable:r!==!1})}}catch(e){c=function(e,t,n){return e[t]=n,e}}p=function(){function e(e,t){this.fn=e,this.self=t,this.next=void 0}var t,n,r;return{add:function(o,i){r=new e(o,i),n?n.next=r:t=r,n=r,r=void 0},drain:function(){var e=t;for(t=n=l=void 0;e;)e.fn.call(e.self),e=e.next}}}();var y=c({},"constructor",f,!1);return f.prototype=y,c(y,"__NPO__",0,!1),c(f,"resolve",function(e){var t=this;return e&&"object"==typeof e&&1===e.__NPO__?e:new t(function(t,n){if("function"!=typeof t||"function"!=typeof n)throw TypeError("Not a function");t(e)})}),c(f,"reject",function(e){return new this(function(t,n){if("function"!=typeof t||"function"!=typeof n)throw TypeError("Not a function");n(e)})}),c(f,"all",function(e){var t=this;return"[object Array]"!=h.call(e)?t.reject(TypeError("Not an array")):0===e.length?t.resolve([]):new t(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");var o=e.length,i=Array(o),a=0;s(t,e,function(e,t){i[e]=t,++a===o&&n(i)},r)})}),c(f,"race",function(e){var t=this;return"[object Array]"!=h.call(e)?t.reject(TypeError("Not an array")):new t(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");s(t,e,function(e,t){n(t)},r)})}),f})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]);
require=function e(t,n,r){function o(s,a){if(!n[s]){if(!t[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:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return o(n?n:e)},c,c.exports,e,t,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(e,t,n){"use strict";n.__esModule=!0,n.default={pool:{size:navigator.hardwareConcurrency||8}}},{}],"./worker":[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t){return e&&t?"/"===e.charAt(e.length-1)||"/"===t.charAt(0)?e+t:e+"/"+t:e+t}function u(e){var t=(0,v.getConfig)().basepath.web;return t?a(t,e):e}function f(e){for(var t=[],n=0;"undefined"!=typeof e[n];)t.push(e[n]),n++;return t}function c(e){if(e.stack)console.error(e.stack);else if(e.message&&e.filename&&e.lineno){var t=e.filename.match(/^data:text\/javascript/)&&e.filename.length>50?e.filename.substr(0,50)+"...":e.filename;console.error(e.message+" @"+t+":"+e.lineno)}else console.error(e)}n.__esModule=!0;var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p=e("eventemitter3"),h=r(p),d=e("./slave-code-uri"),y=r(d),v=e("../config");if("object"!==l(window.Worker)&&"function"!=typeof window.Worker)throw new Error("Browser does not support web workers!");var w=function(e){function t(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];o(this,t);var s=i(this,e.call(this));return s.currentRunnable=null,s.currentImportScripts=[],s.initWorker(),s.worker.addEventListener("message",s.handleMessage.bind(s)),s.worker.addEventListener("error",s.handleError.bind(s)),n&&s.run(n,r),s}return s(t,e),t.prototype.initWorker=function(){try{this.worker=new window.Worker(y.default)}catch(t){var e=(0,v.getConfig)().fallback.slaveScriptUrl;if(!e)throw t;this.worker=new window.Worker(e)}},t.prototype.run=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return this.alreadyInitializedToRun(e,t)?this:("function"==typeof e?this.runMethod(e,t):this.runScripts(e,t),this.currentRunnable=e,this.currentImportScripts=t,this)},t.prototype.runMethod=function(e,t){var n=e.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:t.map(u)})},t.prototype.runScripts=function(e,t){if(!e)throw new Error("Must pass a function or a script URL to run().");this.worker.postMessage({initByScripts:!0,scripts:t.concat([e]).map(u)})},t.prototype.send=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return this.worker.postMessage({doRun:!0,param:e},t),this},t.prototype.kill=function(){return this.worker.terminate(),this.emit("exit"),this},t.prototype.promise=function(){var e=this;return new Promise(function(t,n){var r=void 0,o=void 0;r=function(n){e.removeListener("error",o),t(n)},o=function(t){e.removeListener("message",r),n(t)},e.once("message",r).once("error",o)})},t.prototype.alreadyInitializedToRun=function(e,t){var n=this.currentRunnable===e,r=this.currentImportScripts===t||0===t.length&&0===this.currentImportScripts.length;return n&&r},t.prototype.handleMessage=function(e){if(e.data.error)this.handleError(e.data.error);else if(e.data.progress)this.handleProgress(e.data.progress);else{var t=f(e.data.response);this.emit.apply(this,["message"].concat(t)),this.emit.apply(this,["done"].concat(t))}},t.prototype.handleProgress=function(e){this.emit("progress",e)},t.prototype.handleError=function(e){this.listeners("error",!0)||c(e),e.preventDefault&&e.preventDefault(),this.emit("error",e)},t}(h.default);n.default=w},{"../config":2,"./slave-code-uri":6,eventemitter3:8}],1:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=e("./index"),s=r(i);"object"===("undefined"==typeof window?"undefined":o(window))&&(window.thread=s.default),"function"==typeof define?define([],function(){return s.default}):"object"===("undefined"==typeof t?"undefined":o(t))&&(t.exports=s.default)},{"./index":3}],2:[function(e,t,n){"use strict";function r(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];Object.keys(t).forEach(function(o){var i=t[o],a=n.concat([o]);if("object"===("undefined"==typeof i?"undefined":s(i))){if("undefined"!=typeof e[o]&&"object"!==s(e[o]))throw new Error("Expected config property not to be an object: "+a.join("."));r(e[o],i,a)}else{if("object"===s(e[o]))throw new Error("Expected config property to be an object: "+a.join("."));e[o]=i}})}function o(){return u.get()}function i(){return u.set.apply(u,arguments)}n.__esModule=!0;var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};n.getConfig=o,n.setConfig=i;var a={basepath:{node:"",web:""},fallback:{slaveScriptUrl:""}},u={get:function(){return a},set:function(e){if("object"!==("undefined"==typeof e?"undefined":s(e)))throw new Error("Expected config object.");r(a,e)}};n.default=u},{}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return new p.default(e,t)}n.__esModule=!0,n.Pool=n.defaults=n.config=void 0,n.spawn=o,e("native-promise-only");var i=e("./config"),s=r(i),a=e("./defaults"),u=r(a),f=e("./pool"),c=r(f),l=e("./worker"),p=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:p.default}},{"./config":2,"./defaults":"./defaults","./pool":5,"./worker":"./worker","native-promise-only":9}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}n.__esModule=!0;var a=e("eventemitter3"),u=r(a),f=function(e){function t(n){o(this,t);var r=i(this,e.call(this));return r.pool=n,r.thread=null,r.runArgs=[],r.sendArgs=[],n.emit("newJob",r),r}return s(t,e),t.prototype.run=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];if(0===t.length)throw new Error("Cannot call .run() without arguments.");return this.runArgs=t,this},t.prototype.send=function(){if(0===this.runArgs.length)throw new Error("Cannot .send() before .run().");for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.sendArgs=t,this.emit("readyToRun"),this},t.prototype.executeOn=function(e){var t,n;return(t=(n=e.once("message",this.emit.bind(this,"done")).once("error",this.emit.bind(this,"error"))).run.apply(n,this.runArgs)).send.apply(t,this.sendArgs),this.thread=e,this.emit("threadChanged"),this},t.prototype.promise=function(){var e=this;return new Promise(function(t){e.thread?t(e.thread.promise()):e.once("threadChanged",function(){t(e.thread.promise())})})},t.prototype.destroy=function(){this.removeAllListeners(),delete this.runArgs,delete this.sendArgs},t}(u.default);n.default=f},{eventemitter3:8}],5:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}n.__esModule=!0;var a=e("eventemitter3"),u=r(a),f=e("./job"),c=r(f),l=e("./defaults"),p=r(l),h=e("./"),d=function(e){function t(n){o(this,t);var r=i(this,e.call(this));return r.threads=t.spawn(n||p.default.pool.size),r.idleThreads=r.threads.slice(),r.jobQueue=[],r.runArgs=[],r.on("newJob",function(e){return r.handleNewJob(e)}),r.on("threadAvailable",function(){return r.dequeue()}),r}return s(t,e),t.prototype.run=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.runArgs=t,this},t.prototype.send=function(){var e;if(!this.runArgs)throw new Error("Pool.send() called without prior Pool.run(). You need to define what to run first.");var t=new c.default(this);return(e=t.run.apply(t,this.runArgs)).send.apply(e,arguments)},t.prototype.killAll=function(){this.threads.forEach(function(e){e.kill()})},t.prototype.queueJob=function(e){this.jobQueue.push(e),this.dequeue()},t.prototype.dequeue=function(){var e=this;if(0!==this.jobQueue.length&&0!==this.idleThreads.length){var t=this.jobQueue.shift(),n=this.idleThreads.shift();t.once("done",function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e.handleJobSuccess.apply(e,[n,t].concat(o))}).once("error",function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return e.handleJobError.apply(e,[n,t].concat(o))}),t.executeOn(n)}},t.prototype.handleNewJob=function(e){var t=this;e.once("readyToRun",function(){return t.queueJob(e)})},t.prototype.handleJobSuccess=function(e,t){for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;o<n;o++)r[o-2]=arguments[o];this.emit.apply(this,["done",t].concat(r)),this.handleJobDone(e,t)},t.prototype.handleJobError=function(e,t,n){this.emit("error",t,n),this.handleJobDone(e,t)},t.prototype.handleJobDone=function(e,t){var n=this;t.destroy(),this.idleThreads.push(e),this.emit("threadAvailable"),this.idleThreads.length===this.threads.length&&setTimeout(function(){n.emit("finished")},0)},t}(u.default);n.default=d,d.spawn=function(e){for(var t=[],n=0;n<e;n++)t.push((0,h.spawn)());return t}},{"./":3,"./defaults":"./defaults","./job":4,eventemitter3:8}],6:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}n.__esModule=!0;var o=e("./slave-code"),i=r(o),s="data:text/javascript;charset=utf-8,"+encodeURI(i.default),a=window.createBlobURL||window.createObjectURL;if(!a){var u=window.URL||window.webkitURL;if(!u)throw new Error("No Blob creation implementation found.");a=u.createObjectURL}if("function"==typeof window.BlobBuilder&&"function"==typeof a){var f=new window.BlobBuilder;f.append(i.default),s=a(f.getBlob())}else if("function"==typeof window.Blob&&"function"==typeof a){var c=new window.Blob([i.default],{type:"text/javascript"});s=a(c)}n.default=s},{"./slave-code":7}],7:[function(e,t,n){t.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"},{}],8:[function(e,t,n){"use strict";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(){this._events=new r,this._eventsCount=0}var s=Object.prototype.hasOwnProperty,a="~";Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(a=!1)),i.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)s.call(e,t)&&n.push(a?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},i.prototype.listeners=function(e,t){var n=a?a+e:e,r=this._events[n];if(t)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,i=r.length,s=new Array(i);o<i;o++)s[o]=r[o].fn;return s},i.prototype.emit=function(e,t,n,r,o,i){var s=a?a+e:e;if(!this._events[s])return!1;var u,f,c=this._events[s],l=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,r),!0;case 5:return c.fn.call(c.context,t,n,r,o),!0;case 6:return c.fn.call(c.context,t,n,r,o,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var p,h=c.length;for(f=0;f<h;f++)switch(c[f].once&&this.removeListener(e,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,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,r);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[f].fn.apply(c[f].context,u)}}return!0},i.prototype.on=function(e,t,n){var r=new o(t,n||this),i=a?a+e:e;return this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],r]:this._events[i].push(r):(this._events[i]=r,this._eventsCount++),this},i.prototype.once=function(e,t,n){var r=new o(t,n||this,(!0)),i=a?a+e:e;return this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],r]:this._events[i].push(r):(this._events[i]=r,this._eventsCount++),this},i.prototype.removeListener=function(e,t,n,o){var i=a?a+e:e;if(!this._events[i])return this;if(!t)return 0===--this._eventsCount?this._events=new r:delete this._events[i],this;var s=this._events[i];if(s.fn)s.fn!==t||o&&!s.once||n&&s.context!==n||(0===--this._eventsCount?this._events=new r:delete this._events[i]);else{for(var u=0,f=[],c=s.length;u<c;u++)(s[u].fn!==t||o&&!s[u].once||n&&s[u].context!==n)&&f.push(s[u]);f.length?this._events[i]=1===f.length?f[0]:f:0===--this._eventsCount?this._events=new r:delete this._events[i]}return this},i.prototype.removeAllListeners=function(e){var t;return e?(t=a?a+e:e,this._events[t]&&(0===--this._eventsCount?this._events=new r:delete this._events[t])):(this._events=new r,this._eventsCount=0),this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prototype.setMaxListeners=function(){return this},i.prefixed=a,i.EventEmitter=i,"undefined"!=typeof t&&(t.exports=i)},{}],9:[function(e,t,n){(function(e){!function(e,n,r){n[e]=n[e]||r(),"undefined"!=typeof t&&t.exports?t.exports=n[e]:"function"==typeof define&&define.amd&&define(function(){return n[e]})}("Promise","undefined"!=typeof e?e:this,function(){"use strict";function e(e,t){p.add(e,t),l||(l=d(p.drain))}function t(e){var t,n=typeof e;return null==e||"object"!=n&&"function"!=n||(t=e.then),"function"==typeof t&&t}function n(){for(var e=0;e<this.chain.length;e++)r(this,1===this.state?this.chain[e].success:this.chain[e].failure,this.chain[e]);this.chain.length=0}function r(e,n,r){var o,i;try{n===!1?r.reject(e.msg):(o=n===!0?e.msg:n.call(void 0,e.msg),o===r.promise?r.reject(TypeError("Promise-chain cycle")):(i=t(o))?i.call(o,r.resolve,r.reject):r.resolve(o))}catch(e){r.reject(e)}}function o(r){var s,u=this;if(!u.triggered){u.triggered=!0,u.def&&(u=u.def);try{(s=t(r))?e(function(){var e=new a(u);try{s.call(r,function(){o.apply(e,arguments)},function(){i.apply(e,arguments)})}catch(t){i.call(e,t)}}):(u.msg=r,u.state=1,u.chain.length>0&&e(n,u))}catch(e){i.call(new a(u),e)}}}function i(t){var r=this;r.triggered||(r.triggered=!0,r.def&&(r=r.def),r.msg=t,r.state=2,r.chain.length>0&&e(n,r))}function s(e,t,n,r){for(var o=0;o<t.length;o++)!function(o){e.resolve(t[o]).then(function(e){n(o,e)},r)}(o)}function a(e){this.def=e,this.triggered=!1}function u(e){this.promise=e,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function f(t){if("function"!=typeof t)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(t,o){var i={success:"function"!=typeof t||t,failure:"function"==typeof o&&o};return i.promise=new this.constructor(function(e,t){if("function"!=typeof e||"function"!=typeof t)throw TypeError("Not a function");i.resolve=e,i.reject=t}),r.chain.push(i),0!==r.state&&e(n,r),i.promise},this.catch=function(e){return this.then(void 0,e)};try{t.call(void 0,function(e){o.call(r,e)},function(e){i.call(r,e)})}catch(e){i.call(r,e)}}var c,l,p,h=Object.prototype.toString,d="undefined"!=typeof setImmediate?function(e){return setImmediate(e)}:setTimeout;try{Object.defineProperty({},"x",{}),c=function(e,t,n,r){return Object.defineProperty(e,t,{value:n,writable:!0,configurable:r!==!1})}}catch(e){c=function(e,t,n){return e[t]=n,e}}p=function(){function e(e,t){this.fn=e,this.self=t,this.next=void 0}var t,n,r;return{add:function(o,i){r=new e(o,i),n?n.next=r:t=r,n=r,r=void 0},drain:function(){var e=t;for(t=n=l=void 0;e;)e.fn.call(e.self),e=e.next}}}();var y=c({},"constructor",f,!1);return f.prototype=y,c(y,"__NPO__",0,!1),c(f,"resolve",function(e){var t=this;return e&&"object"==typeof e&&1===e.__NPO__?e:new t(function(t,n){if("function"!=typeof t||"function"!=typeof n)throw TypeError("Not a function");t(e)})}),c(f,"reject",function(e){return new this(function(t,n){if("function"!=typeof t||"function"!=typeof n)throw TypeError("Not a function");n(e)})}),c(f,"all",function(e){var t=this;return"[object Array]"!=h.call(e)?t.reject(TypeError("Not an array")):0===e.length?t.resolve([]):new t(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");var o=e.length,i=Array(o),a=0;s(t,e,function(e,t){i[e]=t,++a===o&&n(i)},r)})}),c(f,"race",function(e){var t=this;return"[object Array]"!=h.call(e)?t.reject(TypeError("Not an array")):new t(function(n,r){if("function"!=typeof n||"function"!=typeof r)throw TypeError("Not a function");s(t,e,function(e,t){n(t)},r)})}),f})}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1]);

@@ -69,3 +69,2 @@ 'use strict';

this.thread = thread;
this.emit('threadChanged');

@@ -91,2 +90,8 @@ return this;

Job.prototype.destroy = function destroy() {
this.removeAllListeners();
delete this.runArgs;
delete this.sendArgs;
};
return Job;

@@ -93,0 +98,0 @@ }(_eventemitter2.default);

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

Pool.prototype.send = function send() {
var _job$run;
if (!this.runArgs) {

@@ -65,4 +67,3 @@ throw new Error('Pool.send() called without prior Pool.run(). You need to define what to run first.');

var job = new _job2.default(this);
job.run.apply(job, this.runArgs);
return job.send.apply(job, arguments);
return (_job$run = job.run.apply(job, this.runArgs)).send.apply(_job$run, arguments);
};

@@ -111,3 +112,2 @@

this.lastCreatedJob = job;
job.once('readyToRun', function () {

@@ -124,3 +124,3 @@ return _this3.queueJob(job);

this.emit.apply(this, ['done', job].concat(responseArgs));
this.handleJobDone(thread);
this.handleJobDone(thread, job);
};

@@ -130,8 +130,9 @@

this.emit('error', job, error);
this.handleJobDone(thread);
this.handleJobDone(thread, job);
};
Pool.prototype.handleJobDone = function handleJobDone(thread) {
Pool.prototype.handleJobDone = function handleJobDone(thread, job) {
var _this4 = this;
job.destroy(); // to prevent memory leak
this.idleThreads.push(thread);

@@ -138,0 +139,0 @@ this.emit('threadAvailable');

@@ -99,3 +99,3 @@ 'use strict';

// try using the slave script file instead of the data URI
this.worker = new window.Worker(_slaveCodeUri2.default);
this.worker = new window.Worker(slaveScriptUrl);
} else {

@@ -102,0 +102,0 @@ // re-throw

@@ -17,7 +17,4 @@ 'use strict';

process.on('uncaughtException', function (error) {
process.send({
error: { message: error.message, stack: error.stack }
});
});
process.on('uncaughtException', messageHandlerError);
process.on('unhandledRejection', messageHandlerError);

@@ -64,2 +61,8 @@ errorCatcherInPlace = true;

function messageHandlerError(error) {
process.send({
error: { message: error.message, stack: error.stack }
});
}
process.on('message', function (data) {

@@ -66,0 +69,0 @@ if (data.initByScript) {

{
"name": "threads",
"version": "0.7.2",
"version": "0.7.3",
"keywords": [

@@ -5,0 +5,0 @@ "threads",

@@ -69,3 +69,3 @@ # threads.js

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

@@ -341,2 +341,3 @@

#### Node: `require()`-ing relative paths in worker does not work (`Error: Cannot find module`)
Thank you, https://github.com/FlorianBruckner, for reporting the issues and helping to debug them!

@@ -343,0 +344,0 @@ **Solution**: Pass down `__dirname` to worker and use it in `require()` (see [Issue 28](https://github.com/andywer/threads.js/issues/28#issuecomment-248505917))

@@ -44,3 +44,2 @@

this.thread = thread;
this.emit('threadChanged');

@@ -63,2 +62,8 @@ return this;

}
destroy () {
this.removeAllListeners();
delete this.runArgs;
delete this.sendArgs;
}
}

@@ -28,5 +28,4 @@ import EventEmitter from 'eventemitter3';

let job = new Job(this);
job.run(...this.runArgs);
return job.send(...args);
const job = new Job(this);
return job.run(...this.runArgs).send(...args);
}

@@ -61,3 +60,2 @@

handleNewJob(job) {
this.lastCreatedJob = job;
job.once('readyToRun', () => this.queueJob(job)); // triggered by job.send()

@@ -68,3 +66,3 @@ }

this.emit('done', job, ...responseArgs);
this.handleJobDone(thread);
this.handleJobDone(thread, job);
}

@@ -74,6 +72,7 @@

this.emit('error', job, error);
this.handleJobDone(thread);
this.handleJobDone(thread, job);
}
handleJobDone(thread) {
handleJobDone(thread, job) {
job.destroy(); // to prevent memory leak
this.idleThreads.push(thread);

@@ -80,0 +79,0 @@ this.emit('threadAvailable');

@@ -77,3 +77,3 @@ import EventEmitter from 'eventemitter3';

// try using the slave script file instead of the data URI
this.worker = new window.Worker(slaveCodeDataUri);
this.worker = new window.Worker(slaveScriptUrl);
} else {

@@ -80,0 +80,0 @@ // re-throw

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

process.on('uncaughtException', function(error) {
process.send({
error : { message : error.message, stack : error.stack }
});
});
process.on('uncaughtException', messageHandlerError);
process.on('unhandledRejection', messageHandlerError);

@@ -54,2 +51,7 @@ errorCatcherInPlace = true;

function messageHandlerError(error) {
process.send({
error : { message : error.message, stack : error.stack }
});
}

@@ -56,0 +58,0 @@ process.on('message', function(data) {

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