Comparing version 0.7.1 to 0.7.2
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){ | ||
/*eslint-env browser*/ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = { | ||
/*eslint-env browser*/ | ||
exports.default = { | ||
pool: { | ||
@@ -12,52 +12,30 @@ size: navigator.hardwareConcurrency || 8 | ||
}; | ||
module.exports = exports["default"]; | ||
//# sourceMappingURL=defaults.browser.js.map | ||
},{}],1:[function(require,module,exports){ | ||
/*eslint-env browser, amd, commonjs*/ | ||
/*global module*/ | ||
},{}],"./worker":[function(require,module,exports){ | ||
'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
exports.__esModule = true; | ||
var _index = require('./index'); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _index2 = _interopRequireDefault(_index); | ||
var _eventemitter = require('eventemitter3'); | ||
if (typeof window === 'object') { | ||
window.thread = _index2['default']; | ||
} | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
if (typeof define === 'function') { | ||
define([], function () { | ||
return _index2['default']; | ||
}); | ||
} else if (typeof module === 'object') { | ||
module.exports = _index2['default']; | ||
} | ||
//# sourceMappingURL=bundle.browser.js.map | ||
var _slaveCodeUri = require('./slave-code-uri'); | ||
},{"./index":3}],"./worker":[function(require,module,exports){ | ||
'use strict'; | ||
var _slaveCodeUri2 = _interopRequireDefault(_slaveCodeUri); | ||
exports.__esModule = true; | ||
var _config = require('../config'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
var _eventemitter3 = require('eventemitter3'); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
var _slaveCodeUri = require('./slave-code-uri'); | ||
var _slaveCodeUri2 = _interopRequireDefault(_slaveCodeUri); | ||
var _config = require('../config'); | ||
if (typeof window.Worker !== 'object' && typeof window.Worker !== 'function') { | ||
if (_typeof(window.Worker) !== 'object' && typeof window.Worker !== 'function') { | ||
throw new Error('Browser does not support web workers!'); | ||
@@ -77,3 +55,3 @@ } | ||
function prependScriptUrl(scriptUrl) { | ||
var prefix = _config.getConfig().basepath.web; | ||
var prefix = (0, _config.getConfig)().basepath.web; | ||
return prefix ? joinPaths(prefix, scriptUrl) : scriptUrl; | ||
@@ -98,31 +76,32 @@ } | ||
} else if (error.message && error.filename && error.lineno) { | ||
var fileName = error.filename.match(/^data:text\/javascript/) && error.filename.length > 50 ? error.filename.substr(0, 50) + '...' : error.filename; | ||
console.error(error.message + ' @' + fileName + ':' + error.lineno); // eslint-disable-line no-console | ||
} else { | ||
console.error(error); // eslint-disable-line no-console | ||
} | ||
var fileName = error.filename.match(/^data:text\/javascript/) && error.filename.length > 50 ? error.filename.substr(0, 50) + '...' : error.filename; | ||
console.error(error.message + ' @' + fileName + ':' + error.lineno); // eslint-disable-line no-console | ||
} else { | ||
console.error(error); // eslint-disable-line no-console | ||
} | ||
} | ||
var Worker = (function (_EventEmitter) { | ||
var Worker = function (_EventEmitter) { | ||
_inherits(Worker, _EventEmitter); | ||
function Worker() { | ||
var initialScript = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var importScripts = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var initialScript = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var importScripts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
_classCallCheck(this, Worker); | ||
_EventEmitter.call(this); | ||
// used by `run()` to decide if the worker must be re-initialized | ||
this.currentRunnable = null; | ||
this.currentImportScripts = []; | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
this.initWorker(); | ||
this.worker.addEventListener('message', this.handleMessage.bind(this)); | ||
this.worker.addEventListener('error', this.handleError.bind(this)); | ||
_this.currentRunnable = null; | ||
_this.currentImportScripts = []; | ||
_this.initWorker(); | ||
_this.worker.addEventListener('message', _this.handleMessage.bind(_this)); | ||
_this.worker.addEventListener('error', _this.handleError.bind(_this)); | ||
if (initialScript) { | ||
this.run(initialScript, importScripts); | ||
_this.run(initialScript, importScripts); | ||
} | ||
return _this; | ||
} | ||
@@ -132,8 +111,8 @@ | ||
try { | ||
this.worker = new window.Worker(_slaveCodeUri2['default']); | ||
this.worker = new window.Worker(_slaveCodeUri2.default); | ||
} catch (error) { | ||
var slaveScriptUrl = _config.getConfig().fallback.slaveScriptUrl; | ||
var slaveScriptUrl = (0, _config.getConfig)().fallback.slaveScriptUrl; | ||
if (slaveScriptUrl) { | ||
// try using the slave script file instead of the data URI | ||
this.worker = new window.Worker(_slaveCodeUri2['default']); | ||
this.worker = new window.Worker(_slaveCodeUri2.default); | ||
} else { | ||
@@ -147,3 +126,3 @@ // re-throw | ||
Worker.prototype.run = function run(toRun) { | ||
var importScripts = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var importScripts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
@@ -192,3 +171,3 @@ if (this.alreadyInitializedToRun(toRun, importScripts)) { | ||
Worker.prototype.send = function send(param) { | ||
var transferables = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var transferables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
@@ -209,6 +188,17 @@ this.worker.postMessage({ | ||
Worker.prototype.promise = function promise() { | ||
var _this = this; | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.once('message', resolve).once('error', reject); | ||
var resolved = void 0, | ||
rejected = void 0; | ||
resolved = function resolved(result) { | ||
_this2.removeListener('error', rejected); | ||
resolve(result); | ||
}; | ||
rejected = function rejected(err) { | ||
_this2.removeListener('message', resolved); | ||
reject(err); | ||
}; | ||
_this2.once('message', resolved).once('error', rejected); | ||
}); | ||
@@ -253,12 +243,39 @@ }; | ||
return Worker; | ||
})(_eventemitter32['default']); | ||
}(_eventemitter2.default); | ||
exports['default'] = Worker; | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=worker.js.map | ||
exports.default = Worker; | ||
},{"../config":2,"./slave-code-uri":6,"eventemitter3":8}],2:[function(require,module,exports){ | ||
},{"../config":2,"./slave-code-uri":6,"eventemitter3":8}],1:[function(require,module,exports){ | ||
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*eslint-env browser, amd, commonjs*/ | ||
/*global module*/ | ||
var _index = require('./index'); | ||
var _index2 = _interopRequireDefault(_index); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object') { | ||
window.thread = _index2.default; | ||
} | ||
if (typeof define === 'function') { | ||
define([], function () { | ||
return _index2.default; | ||
}); | ||
} else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') { | ||
module.exports = _index2.default; | ||
} | ||
},{"./index":3}],2:[function(require,module,exports){ | ||
'use strict'; | ||
exports.__esModule = true; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.getConfig = getConfig; | ||
@@ -277,3 +294,3 @@ exports.setConfig = setConfig; | ||
function configDeepMerge(destObj, srcObj) { | ||
var ancestorProps = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; | ||
var ancestorProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
@@ -284,4 +301,4 @@ Object.keys(srcObj).forEach(function (propKey) { | ||
if (typeof srcValue === 'object') { | ||
if (typeof destObj[propKey] !== 'undefined' && typeof destObj[propKey] !== 'object') { | ||
if ((typeof srcValue === 'undefined' ? 'undefined' : _typeof(srcValue)) === 'object') { | ||
if (typeof destObj[propKey] !== 'undefined' && _typeof(destObj[propKey]) !== 'object') { | ||
throw new Error('Expected config property not to be an object: ' + ancestorPropsAndThis.join('.')); | ||
@@ -291,3 +308,3 @@ } | ||
} else { | ||
if (typeof destObj[propKey] === 'object') { | ||
if (_typeof(destObj[propKey]) === 'object') { | ||
throw new Error('Expected config property to be an object: ' + ancestorPropsAndThis.join('.')); | ||
@@ -306,3 +323,3 @@ } | ||
set: function set(newConfig) { | ||
if (typeof newConfig !== 'object') { | ||
if ((typeof newConfig === 'undefined' ? 'undefined' : _typeof(newConfig)) !== 'object') { | ||
throw new Error('Expected config object.'); | ||
@@ -315,4 +332,3 @@ } | ||
exports['default'] = config; | ||
exports.default = config; | ||
function getConfig() { | ||
@@ -325,4 +341,4 @@ return config.get(); | ||
} | ||
//# sourceMappingURL=config.js.map | ||
},{}],3:[function(require,module,exports){ | ||
@@ -332,6 +348,5 @@ 'use strict'; | ||
exports.__esModule = true; | ||
exports.Pool = exports.defaults = exports.config = undefined; | ||
exports.spawn = spawn; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
require('native-promise-only'); | ||
@@ -355,22 +370,23 @@ | ||
exports.config = _config2['default']; | ||
exports.defaults = _defaults2['default']; | ||
exports.Pool = _pool2['default']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.config = _config2.default; | ||
exports.defaults = _defaults2.default; | ||
exports.Pool = _pool2.default; | ||
function spawn() { | ||
var runnable = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var importScripts = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var runnable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var importScripts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
return new _worker2['default'](runnable, importScripts); | ||
return new _worker2.default(runnable, importScripts); | ||
} | ||
exports['default'] = { | ||
config: _config2['default'], | ||
defaults: _defaults2['default'], | ||
Pool: _pool2['default'], | ||
exports.default = { | ||
config: _config2.default, | ||
defaults: _defaults2.default, | ||
Pool: _pool2.default, | ||
spawn: spawn, | ||
Worker: _worker2['default'] | ||
Worker: _worker2.default | ||
}; | ||
//# sourceMappingURL=index.js.map | ||
},{"./config":2,"./defaults":"./defaults","./pool":5,"./worker":"./worker","native-promise-only":9}],4:[function(require,module,exports){ | ||
@@ -381,13 +397,15 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _eventemitter = require('eventemitter3'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _eventemitter3 = require('eventemitter3'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
var Job = (function (_EventEmitter) { | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Job = function (_EventEmitter) { | ||
_inherits(Job, _EventEmitter); | ||
@@ -398,10 +416,12 @@ | ||
_EventEmitter.call(this); | ||
this.pool = pool; | ||
this.thread = null; | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
this.runArgs = []; | ||
this.sendArgs = []; | ||
_this.pool = pool; | ||
_this.thread = null; | ||
pool.emit('newJob', this); | ||
_this.runArgs = []; | ||
_this.sendArgs = []; | ||
pool.emit('newJob', _this); | ||
return _this; | ||
} | ||
@@ -449,3 +469,3 @@ | ||
Job.prototype.promise = function promise() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -455,8 +475,8 @@ // Always return a promise | ||
// If the thread isn't set, listen for the threadChanged event | ||
if (!_this.thread) { | ||
_this.once('threadChanged', function () { | ||
resolve(_this.thread.promise()); | ||
if (!_this2.thread) { | ||
_this2.once('threadChanged', function () { | ||
resolve(_this2.thread.promise()); | ||
}); | ||
} else { | ||
resolve(_this.thread.promise()); | ||
resolve(_this2.thread.promise()); | ||
} | ||
@@ -467,8 +487,7 @@ }); | ||
return Job; | ||
})(_eventemitter32['default']); | ||
}(_eventemitter2.default); | ||
exports['default'] = Job; | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=job.js.map | ||
exports.default = Job; | ||
},{"eventemitter3":8}],5:[function(require,module,exports){ | ||
@@ -479,12 +498,6 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _eventemitter = require('eventemitter3'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _eventemitter3 = require('eventemitter3'); | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
var _job = require('./job'); | ||
@@ -500,22 +513,30 @@ | ||
var Pool = (function (_EventEmitter) { | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Pool = function (_EventEmitter) { | ||
_inherits(Pool, _EventEmitter); | ||
function Pool(threads) { | ||
var _this = this; | ||
_classCallCheck(this, Pool); | ||
_EventEmitter.call(this); | ||
this.threads = Pool.spawn(threads || _defaults2['default'].pool.size); | ||
this.idleThreads = this.threads.slice(); | ||
this.jobQueue = []; | ||
this.runArgs = []; | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
this.on('newJob', function (job) { | ||
_this.threads = Pool.spawn(threads || _defaults2.default.pool.size); | ||
_this.idleThreads = _this.threads.slice(); | ||
_this.jobQueue = []; | ||
_this.runArgs = []; | ||
_this.on('newJob', function (job) { | ||
return _this.handleNewJob(job); | ||
}); | ||
this.on('threadAvailable', function () { | ||
_this.on('threadAvailable', function () { | ||
return _this.dequeue(); | ||
}); | ||
return _this; | ||
} | ||
@@ -537,3 +558,3 @@ | ||
var job = new _job2['default'](this); | ||
var job = new _job2.default(this); | ||
job.run.apply(job, this.runArgs); | ||
@@ -619,6 +640,7 @@ return job.send.apply(job, arguments); | ||
return Pool; | ||
})(_eventemitter32['default']); | ||
}(_eventemitter2.default); | ||
exports['default'] = Pool; | ||
exports.default = Pool; | ||
Pool.spawn = function (threadCount) { | ||
@@ -628,3 +650,3 @@ var threads = []; | ||
for (var threadIndex = 0; threadIndex < threadCount; threadIndex++) { | ||
threads.push(_.spawn()); | ||
threads.push((0, _.spawn)()); | ||
} | ||
@@ -634,5 +656,4 @@ | ||
}; | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=pool.js.map | ||
},{"./":3,"./defaults":"./defaults","./job":4,"eventemitter3":8}],6:[function(require,module,exports){ | ||
@@ -643,4 +664,2 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _slaveCode = require('./slave-code'); | ||
@@ -650,10 +669,12 @@ | ||
var slaveCodeDataUri = 'data:text/javascript;charset=utf-8,' + encodeURI(_slaveCode2['default']); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var slaveCodeDataUri = 'data:text/javascript;charset=utf-8,' + encodeURI(_slaveCode2.default); | ||
var createBlobURL = window.createBlobURL || window.createObjectURL; | ||
if (!createBlobURL) { | ||
var _URL = window.URL || window.webkitURL; | ||
var URL = window.URL || window.webkitURL; | ||
if (_URL) { | ||
createBlobURL = _URL.createObjectURL; | ||
if (URL) { | ||
createBlobURL = URL.createObjectURL; | ||
} else { | ||
@@ -666,13 +687,12 @@ throw new Error('No Blob creation implementation found.'); | ||
var blobBuilder = new window.BlobBuilder(); | ||
blobBuilder.append(_slaveCode2['default']); | ||
blobBuilder.append(_slaveCode2.default); | ||
slaveCodeDataUri = createBlobURL(blobBuilder.getBlob()); | ||
} else if (typeof window.Blob === 'function' && typeof createBlobURL === 'function') { | ||
var blob = new window.Blob([_slaveCode2['default']], { type: 'text/javascript' }); | ||
var blob = new window.Blob([_slaveCode2.default], { type: 'text/javascript' }); | ||
slaveCodeDataUri = createBlobURL(blob); | ||
} | ||
exports['default'] = slaveCodeDataUri; | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=slave-code-uri.js.map | ||
exports.default = slaveCodeDataUri; | ||
},{"./slave-code":7}],7:[function(require,module,exports){ | ||
@@ -683,20 +703,38 @@ 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"; | ||
var has = Object.prototype.hasOwnProperty; | ||
var has = Object.prototype.hasOwnProperty | ||
, prefix = '~'; | ||
/** | ||
* Constructor to create a storage for our `EE` objects. | ||
* An `Events` instance is a plain object whose properties are event names. | ||
* | ||
* @constructor | ||
* @api private | ||
*/ | ||
function Events() {} | ||
// | ||
// We store our EE objects in a plain object whose properties are event names. | ||
// We try to not inherit from `Object.prototype`. In some engines creating an | ||
// instance in this way is faster than calling `Object.create(null)` directly. | ||
// If `Object.create(null)` is not supported we prefix the event names with a | ||
// `~` to make sure that the built-in object properties are not overridden or | ||
// used as an attack vector. | ||
// We also assume that `Object.create(null)` is available when the event name | ||
// is an ES6 Symbol. | ||
// character to make sure that the built-in object properties are not | ||
// overridden or used as an attack vector. | ||
// | ||
var prefix = typeof Object.create !== 'function' ? '~' : false; | ||
if (Object.create) { | ||
Events.prototype = Object.create(null); | ||
// | ||
// This hack is needed because the `__proto__` property is still inherited in | ||
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5. | ||
// | ||
if (!new Events().__proto__) prefix = false; | ||
} | ||
/** | ||
* Representation of a single EventEmitter function. | ||
* Representation of a single event listener. | ||
* | ||
* @param {Function} fn Event handler to be called. | ||
* @param {Mixed} context Context for function execution. | ||
* @param {Boolean} [once=false] Only emit once | ||
* @param {Function} fn The listener function. | ||
* @param {Mixed} context The context to invoke the listener with. | ||
* @param {Boolean} [once=false] Specify if the listener is a one-time listener. | ||
* @constructor | ||
* @api private | ||
@@ -711,4 +749,4 @@ */ | ||
/** | ||
* Minimal EventEmitter interface that is molded against the Node.js | ||
* EventEmitter interface. | ||
* Minimal `EventEmitter` interface that is molded against the Node.js | ||
* `EventEmitter` interface. | ||
* | ||
@@ -718,13 +756,8 @@ * @constructor | ||
*/ | ||
function EventEmitter() { /* Nothing to set */ } | ||
function EventEmitter() { | ||
this._events = new Events(); | ||
this._eventsCount = 0; | ||
} | ||
/** | ||
* Hold the assigned EventEmitters by name. | ||
* | ||
* @type {Object} | ||
* @private | ||
*/ | ||
EventEmitter.prototype._events = undefined; | ||
/** | ||
* Return an array listing the events for which the emitter has registered | ||
@@ -737,9 +770,9 @@ * listeners. | ||
EventEmitter.prototype.eventNames = function eventNames() { | ||
var events = this._events | ||
, names = [] | ||
var names = [] | ||
, events | ||
, name; | ||
if (!events) return names; | ||
if (this._eventsCount === 0) return names; | ||
for (name in events) { | ||
for (name in (events = this._events)) { | ||
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name); | ||
@@ -756,6 +789,6 @@ } | ||
/** | ||
* Return a list of assigned event listeners. | ||
* Return the listeners registered for a given event. | ||
* | ||
* @param {String} event The events that should be listed. | ||
* @param {Boolean} exists We only need to know if there are listeners. | ||
* @param {String|Symbol} event The event name. | ||
* @param {Boolean} exists Only check if there are listeners. | ||
* @returns {Array|Boolean} | ||
@@ -766,3 +799,3 @@ * @api public | ||
var evt = prefix ? prefix + event : event | ||
, available = this._events && this._events[evt]; | ||
, available = this._events[evt]; | ||
@@ -781,6 +814,6 @@ if (exists) return !!available; | ||
/** | ||
* Emit an event to all registered event listeners. | ||
* Calls each of the listeners registered for a given event. | ||
* | ||
* @param {String} event The name of the event. | ||
* @returns {Boolean} Indication if we've emitted an event. | ||
* @param {String|Symbol} event The event name. | ||
* @returns {Boolean} `true` if the event had listeners, else `false`. | ||
* @api public | ||
@@ -791,3 +824,3 @@ */ | ||
if (!this._events || !this._events[evt]) return false; | ||
if (!this._events[evt]) return false; | ||
@@ -799,3 +832,3 @@ var listeners = this._events[evt] | ||
if ('function' === typeof listeners.fn) { | ||
if (listeners.fn) { | ||
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true); | ||
@@ -828,2 +861,3 @@ | ||
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; | ||
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; | ||
default: | ||
@@ -843,7 +877,8 @@ if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { | ||
/** | ||
* Register a new EventListener for the given event. | ||
* Add a listener for a given event. | ||
* | ||
* @param {String} event Name of the event. | ||
* @param {Function} fn Callback function. | ||
* @param {Mixed} [context=this] The context of the function. | ||
* @param {String|Symbol} event The event name. | ||
* @param {Function} fn The listener function. | ||
* @param {Mixed} [context=this] The context to invoke the listener with. | ||
* @returns {EventEmitter} `this`. | ||
* @api public | ||
@@ -855,10 +890,5 @@ */ | ||
if (!this._events) this._events = prefix ? {} : Object.create(null); | ||
if (!this._events[evt]) this._events[evt] = listener; | ||
else { | ||
if (!this._events[evt].fn) this._events[evt].push(listener); | ||
else this._events[evt] = [ | ||
this._events[evt], listener | ||
]; | ||
} | ||
if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++; | ||
else if (!this._events[evt].fn) this._events[evt].push(listener); | ||
else this._events[evt] = [this._events[evt], listener]; | ||
@@ -869,7 +899,8 @@ return this; | ||
/** | ||
* Add an EventListener that's only called once. | ||
* Add a one-time listener for a given event. | ||
* | ||
* @param {String} event Name of the event. | ||
* @param {Function} fn Callback function. | ||
* @param {Mixed} [context=this] The context of the function. | ||
* @param {String|Symbol} event The event name. | ||
* @param {Function} fn The listener function. | ||
* @param {Mixed} [context=this] The context to invoke the listener with. | ||
* @returns {EventEmitter} `this`. | ||
* @api public | ||
@@ -881,10 +912,5 @@ */ | ||
if (!this._events) this._events = prefix ? {} : Object.create(null); | ||
if (!this._events[evt]) this._events[evt] = listener; | ||
else { | ||
if (!this._events[evt].fn) this._events[evt].push(listener); | ||
else this._events[evt] = [ | ||
this._events[evt], listener | ||
]; | ||
} | ||
if (!this._events[evt]) this._events[evt] = listener, this._eventsCount++; | ||
else if (!this._events[evt].fn) this._events[evt].push(listener); | ||
else this._events[evt] = [this._events[evt], listener]; | ||
@@ -895,8 +921,9 @@ return this; | ||
/** | ||
* Remove event listeners. | ||
* Remove the listeners of a given event. | ||
* | ||
* @param {String} event The event we want to remove. | ||
* @param {Function} fn The listener that we need to find. | ||
* @param {Mixed} context Only remove listeners matching this context. | ||
* @param {Boolean} once Only remove once listeners. | ||
* @param {String|Symbol} event The event name. | ||
* @param {Function} fn Only remove the listeners that match this function. | ||
* @param {Mixed} context Only remove the listeners that have this context. | ||
* @param {Boolean} once Only remove one-time listeners. | ||
* @returns {EventEmitter} `this`. | ||
* @api public | ||
@@ -907,36 +934,37 @@ */ | ||
if (!this._events || !this._events[evt]) return this; | ||
if (!this._events[evt]) return this; | ||
if (!fn) { | ||
if (--this._eventsCount === 0) this._events = new Events(); | ||
else delete this._events[evt]; | ||
return this; | ||
} | ||
var listeners = this._events[evt] | ||
, events = []; | ||
var listeners = this._events[evt]; | ||
if (fn) { | ||
if (listeners.fn) { | ||
if (listeners.fn) { | ||
if ( | ||
listeners.fn === fn | ||
&& (!once || listeners.once) | ||
&& (!context || listeners.context === context) | ||
) { | ||
if (--this._eventsCount === 0) this._events = new Events(); | ||
else delete this._events[evt]; | ||
} | ||
} else { | ||
for (var i = 0, events = [], length = listeners.length; i < length; i++) { | ||
if ( | ||
listeners.fn !== fn | ||
|| (once && !listeners.once) | ||
|| (context && listeners.context !== context) | ||
listeners[i].fn !== fn | ||
|| (once && !listeners[i].once) | ||
|| (context && listeners[i].context !== context) | ||
) { | ||
events.push(listeners); | ||
events.push(listeners[i]); | ||
} | ||
} else { | ||
for (var i = 0, length = listeners.length; i < length; i++) { | ||
if ( | ||
listeners[i].fn !== fn | ||
|| (once && !listeners[i].once) | ||
|| (context && listeners[i].context !== context) | ||
) { | ||
events.push(listeners[i]); | ||
} | ||
} | ||
} | ||
} | ||
// | ||
// Reset the array, or remove it completely if we have no more listeners. | ||
// | ||
if (events.length) { | ||
this._events[evt] = events.length === 1 ? events[0] : events; | ||
} else { | ||
delete this._events[evt]; | ||
// | ||
// Reset the array, or remove it completely if we have no more listeners. | ||
// | ||
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events; | ||
else if (--this._eventsCount === 0) this._events = new Events(); | ||
else delete this._events[evt]; | ||
} | ||
@@ -948,12 +976,21 @@ | ||
/** | ||
* Remove all listeners or only the listeners for the specified event. | ||
* Remove all listeners, or those of the specified event. | ||
* | ||
* @param {String} event The event want to remove all listeners for. | ||
* @param {String|Symbol} [event] The event name. | ||
* @returns {EventEmitter} `this`. | ||
* @api public | ||
*/ | ||
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { | ||
if (!this._events) return this; | ||
var evt; | ||
if (event) delete this._events[prefix ? prefix + event : event]; | ||
else this._events = prefix ? {} : Object.create(null); | ||
if (event) { | ||
evt = prefix ? prefix + event : event; | ||
if (this._events[evt]) { | ||
if (--this._eventsCount === 0) this._events = new Events(); | ||
else delete this._events[evt]; | ||
} | ||
} else { | ||
this._events = new Events(); | ||
this._eventsCount = 0; | ||
} | ||
@@ -982,2 +1019,7 @@ return this; | ||
// | ||
// Allow `EventEmitter` to be imported as module namespace. | ||
// | ||
EventEmitter.EventEmitter = EventEmitter; | ||
// | ||
// Expose the module. | ||
@@ -984,0 +1026,0 @@ // |
@@ -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 c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[s]={exports:{}};e[s][0].call(f.exports,function(t){var n=e[s][1][t];return o(n?n:t)},f,f.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,e){return t&&e?"/"===t.charAt(t.length-1)||"/"===e.charAt(0)?t+e:t+"/"+e:t+e}function a(t){var e=d.getConfig().basepath.web;return e?s(e,t):t}function u(t){for(var e=[],n=0;"undefined"!=typeof t[n];)e.push(t[n]),n++;return e}function c(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"),l=r(f),h=t("./slave-code-uri"),p=r(h),d=t("../config");if("object"!=typeof window.Worker&&"function"!=typeof window.Worker)throw new Error("Browser does not support web workers!");var 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.currentRunnable=null,this.currentImportScripts=[],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(p["default"])}catch(t){var e=d.getConfig().fallback.slaveScriptUrl;if(!e)throw t;this.worker=new window.Worker(p["default"])}},e.prototype.run=function(t){var e=arguments.length<=1||void 0===arguments[1]?[]:arguments[1];return this.alreadyInitializedToRun(t,e)?this:("function"==typeof t?this.runMethod(t,e):this.runScripts(t,e),this.currentRunnable=t,this.currentImportScripts=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(a)})},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(a)})},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.alreadyInitializedToRun=function(t,e){var n=this.currentRunnable===t,r=this.currentImportScripts===e||0===e.length&&0===this.currentImportScripts.length;return n&&r},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=u(t.data.response);this.emit.apply(this,["message"].concat(e)),this.emit.apply(this,["done"].concat(e))}},e.prototype.handleProgress=function(t){this.emit("progress",t)},e.prototype.handleError=function(t){this.listeners("error",!0)||c(t),t.preventDefault&&t.preventDefault(),this.emit("error",t)},e}(l["default"]);n["default"]=y,e.exports=n["default"]},{"../config":2,"./slave-code-uri":6,eventemitter3:8}],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),c=t("./pool"),f=r(c),l=t("./worker"),h=r(l);n.config=s["default"],n.defaults=u["default"],n.Pool=f["default"],n["default"]={config:s["default"],defaults:u["default"],Pool:f["default"],spawn:o,Worker:h["default"]}},{"./config":2,"./defaults":"./defaults","./pool":5,"./worker":"./worker","native-promise-only":9}],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.sendArgs=[],n.emit("newJob",this)}return i(e,t),e.prototype.run=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;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;n<t;n++)e[n]=arguments[n];return this.sendArgs=e,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.emit("threadChanged"),this},e.prototype.promise=function(){var t=this;return new Promise(function(e){t.thread?e(t.thread.promise()):t.once("threadChanged",function(){e(t.thread.promise())})})},e}(a["default"]);n["default"]=u,e.exports=n["default"]},{eventemitter3:8}],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"),c=r(u),f=t("./defaults"),l=r(f),h=t("./"),p=function(t){function e(n){var r=this;o(this,e),t.call(this),this.threads=e.spawn(n||l["default"].pool.size),this.idleThreads=this.threads.slice(),this.jobQueue=[],this.runArgs=[],this.on("newJob",function(t){return r.handleNewJob(t)}),this.on("threadAvailable",function(){return r.dequeue()})}return i(e,t),e.prototype.run=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return this.runArgs=e,this},e.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 t=new c["default"](this);return t.run.apply(t,this.runArgs),t.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(){var t=this;if(0!==this.jobQueue.length&&0!==this.idleThreads.length){var e=this.jobQueue.shift(),n=this.idleThreads.shift();e.once("done",function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return t.handleJobSuccess.apply(t,[n,e].concat(o))}).once("error",function(){for(var r=arguments.length,o=Array(r),i=0;i<r;i++)o[i]=arguments[i];return t.handleJobError.apply(t,[n,e].concat(o))}),e.executeOn(n)}},e.prototype.handleNewJob=function(t){var e=this;this.lastCreatedJob=t,t.once("readyToRun",function(){return e.queueJob(t)})},e.prototype.handleJobSuccess=function(t,e){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",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.emit("threadAvailable"),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;n<t;n++)e.push(h.spawn());return e},e.exports=n["default"]},{"./":3,"./defaults":"./defaults","./job":4,eventemitter3:8}],6:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}n.__esModule=!0;var o=t("./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 c=new window.BlobBuilder;c.append(i["default"]),s=a(c.getBlob())}else if("function"==typeof window.Blob&&"function"==typeof a){var f=new window.Blob([i["default"]],{type:"text/javascript"});s=a(f)}n["default"]=s,e.exports=n["default"]},{"./slave-code":7}],7:[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"},{}],8:[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=Object.prototype.hasOwnProperty,s="function"!=typeof Object.create&&"~";o.prototype._events=void 0,o.prototype.eventNames=function(){var t,e=this._events,n=[];if(!e)return n;for(t in e)i.call(e,t)&&n.push(s?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},o.prototype.listeners=function(t,e){var n=s?s+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,i=r.length,a=new Array(i);o<i;o++)a[o]=r[o].fn;return a},o.prototype.emit=function(t,e,n,r,o,i){var a=s?s+t:t;if(!this._events||!this._events[a])return!1;var u,c,f=this._events[a],l=arguments.length;if("function"==typeof f.fn){switch(f.once&&this.removeListener(t,f.fn,void 0,!0),l){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,e),!0;case 3:return f.fn.call(f.context,e,n),!0;case 4:return f.fn.call(f.context,e,n,r),!0;case 5:return f.fn.call(f.context,e,n,r,o),!0;case 6:return f.fn.call(f.context,e,n,r,o,i),!0}for(c=1,u=new Array(l-1);c<l;c++)u[c-1]=arguments[c];f.fn.apply(f.context,u)}else{var h,p=f.length;for(c=0;c<p;c++)switch(f[c].once&&this.removeListener(t,f[c].fn,void 0,!0),l){case 1:f[c].fn.call(f[c].context);break;case 2:f[c].fn.call(f[c].context,e);break;case 3:f[c].fn.call(f[c].context,e,n);break;default:if(!u)for(h=1,u=new Array(l-1);h<l;h++)u[h-1]=arguments[h];f[c].fn.apply(f[c].context,u)}}return!0},o.prototype.on=function(t,e,n){var o=new r(e,n||this),i=s?s+t:t;return this._events||(this._events=s?{}:Object.create(null)),this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],o]:this._events[i].push(o):this._events[i]=o,this},o.prototype.once=function(t,e,n){var o=new r(e,n||this,(!0)),i=s?s+t:t;return this._events||(this._events=s?{}:Object.create(null)),this._events[i]?this._events[i].fn?this._events[i]=[this._events[i],o]:this._events[i].push(o):this._events[i]=o,this},o.prototype.removeListener=function(t,e,n,r){var o=s?s+t:t;if(!this._events||!this._events[o])return this;var i=this._events[o],a=[];if(e)if(i.fn)(i.fn!==e||r&&!i.once||n&&i.context!==n)&&a.push(i);else for(var u=0,c=i.length;u<c;u++)(i[u].fn!==e||r&&!i[u].once||n&&i[u].context!==n)&&a.push(i[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[s?s+t:t]:this._events=s?{}: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=s,"undefined"!=typeof e&&(e.exports=o)},{}],9:[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}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(c){i.call(new a(u),c)}}}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 c(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,failure:"function"==typeof o&&o};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 f,l,h,p=Object.prototype.toString,d="undefined"!=typeof setImmediate?function(t){return setImmediate(t)}:setTimeout;try{Object.defineProperty({},"x",{}),f=function(t,e,n,r){return Object.defineProperty(t,e,{value:n,writable:!0,configurable:r!==!1})}}catch(y){f=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=f({},"constructor",c,!1);return c.prototype=v,f(v,"__NPO__",0,!1),f(c,"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)})}),f(c,"reject",function(t){return new this(function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");n(t)})}),f(c,"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)})}),f(c,"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)})}),c})}).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(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]); |
@@ -55,3 +55,3 @@ /*eslint-env node*/ | ||
gulp.task('lint', function() { | ||
return gulp.src(['src/**/*.js', 'src/**/*.js.txt', 'test/spec-src/*.js']) | ||
return gulp.src(['src/**/*.js', 'src/**/*.js.txt', 'test/spec/*.js']) | ||
.pipe(eslint()) | ||
@@ -73,3 +73,3 @@ .pipe(eslint.format()) | ||
.pipe(sourcemaps.init()) | ||
.pipe(babel({ loose : 'all' })) | ||
.pipe(babel()) | ||
.pipe(sourcemaps.write('.')) | ||
@@ -80,5 +80,5 @@ .pipe(gulp.dest('lib/')); | ||
gulp.task('babel-spec', function() { | ||
return gulp.src('test/spec-src/**/*.js') | ||
return gulp.src('test/spec/**/*.js') | ||
.pipe(babel()) | ||
.pipe(gulp.dest('test/spec')); | ||
.pipe(gulp.dest('test/spec-build')); | ||
}); | ||
@@ -133,3 +133,3 @@ | ||
gulp.task('test-node', ['dist', 'babel-spec'], function() { | ||
return gulp.src('test/spec/*.spec.js', { read: false }) | ||
return gulp.src('test/spec-build/*.spec.js', { read: false }) | ||
.pipe(mocha()); | ||
@@ -136,0 +136,0 @@ }); |
@@ -14,3 +14,3 @@ // Karma configuration | ||
files: [ | ||
'test/spec/*.spec.js', | ||
'test/spec-build/*.spec.js', | ||
{ pattern : 'test/thread-scripts/*.js', included : false } | ||
@@ -27,3 +27,3 @@ ], | ||
preprocessors: { | ||
'test/spec/*.spec.js': ['browserify'] | ||
'test/spec-build/*.spec.js': ['browserify'] | ||
}, | ||
@@ -30,0 +30,0 @@ |
@@ -1,7 +0,5 @@ | ||
/*eslint-env browser, amd, commonjs*/ | ||
/*global module*/ | ||
'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*eslint-env browser, amd, commonjs*/ | ||
/*global module*/ | ||
@@ -12,4 +10,6 @@ var _index = require('./index'); | ||
if (typeof window === 'object') { | ||
window.thread = _index2['default']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object') { | ||
window.thread = _index2.default; | ||
} | ||
@@ -19,7 +19,7 @@ | ||
define([], function () { | ||
return _index2['default']; | ||
return _index2.default; | ||
}); | ||
} else if (typeof module === 'object') { | ||
module.exports = _index2['default']; | ||
} else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') { | ||
module.exports = _index2.default; | ||
} | ||
//# sourceMappingURL=bundle.browser.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.getConfig = getConfig; | ||
@@ -17,3 +20,3 @@ exports.setConfig = setConfig; | ||
function configDeepMerge(destObj, srcObj) { | ||
var ancestorProps = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; | ||
var ancestorProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
@@ -24,4 +27,4 @@ Object.keys(srcObj).forEach(function (propKey) { | ||
if (typeof srcValue === 'object') { | ||
if (typeof destObj[propKey] !== 'undefined' && typeof destObj[propKey] !== 'object') { | ||
if ((typeof srcValue === 'undefined' ? 'undefined' : _typeof(srcValue)) === 'object') { | ||
if (typeof destObj[propKey] !== 'undefined' && _typeof(destObj[propKey]) !== 'object') { | ||
throw new Error('Expected config property not to be an object: ' + ancestorPropsAndThis.join('.')); | ||
@@ -31,3 +34,3 @@ } | ||
} else { | ||
if (typeof destObj[propKey] === 'object') { | ||
if (_typeof(destObj[propKey]) === 'object') { | ||
throw new Error('Expected config property to be an object: ' + ancestorPropsAndThis.join('.')); | ||
@@ -46,3 +49,3 @@ } | ||
set: function set(newConfig) { | ||
if (typeof newConfig !== 'object') { | ||
if ((typeof newConfig === 'undefined' ? 'undefined' : _typeof(newConfig)) !== 'object') { | ||
throw new Error('Expected config object.'); | ||
@@ -55,4 +58,3 @@ } | ||
exports['default'] = config; | ||
exports.default = config; | ||
function getConfig() { | ||
@@ -59,0 +61,0 @@ return config.get(); |
@@ -1,7 +0,7 @@ | ||
/*eslint-env browser*/ | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = { | ||
/*eslint-env browser*/ | ||
exports.default = { | ||
pool: { | ||
@@ -11,3 +11,2 @@ size: navigator.hardwareConcurrency || 8 | ||
}; | ||
module.exports = exports["default"]; | ||
//# sourceMappingURL=defaults.browser.js.map |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/*eslint-env node*/ | ||
@@ -8,4 +10,2 @@ /* | ||
'use strict'; | ||
if (typeof process !== 'undefined' && 'pid' in process) { | ||
@@ -12,0 +12,0 @@ module.exports = require('./defaults.node'); |
@@ -7,8 +7,7 @@ 'use strict'; | ||
exports['default'] = { | ||
exports.default = { | ||
pool: { | ||
size: _os.cpus().length | ||
size: (0, _os.cpus)().length | ||
} | ||
}; | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=defaults.node.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.Pool = exports.defaults = exports.config = undefined; | ||
exports.spawn = spawn; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
require('native-promise-only'); | ||
@@ -26,20 +25,21 @@ | ||
exports.config = _config2['default']; | ||
exports.defaults = _defaults2['default']; | ||
exports.Pool = _pool2['default']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.config = _config2.default; | ||
exports.defaults = _defaults2.default; | ||
exports.Pool = _pool2.default; | ||
function spawn() { | ||
var runnable = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var importScripts = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var runnable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var importScripts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
return new _worker2['default'](runnable, importScripts); | ||
return new _worker2.default(runnable, importScripts); | ||
} | ||
exports['default'] = { | ||
config: _config2['default'], | ||
defaults: _defaults2['default'], | ||
Pool: _pool2['default'], | ||
exports.default = { | ||
config: _config2.default, | ||
defaults: _defaults2.default, | ||
Pool: _pool2.default, | ||
spawn: spawn, | ||
Worker: _worker2['default'] | ||
Worker: _worker2.default | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -5,13 +5,15 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _eventemitter = require('eventemitter3'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _eventemitter3 = require('eventemitter3'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
var Job = (function (_EventEmitter) { | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Job = function (_EventEmitter) { | ||
_inherits(Job, _EventEmitter); | ||
@@ -22,10 +24,12 @@ | ||
_EventEmitter.call(this); | ||
this.pool = pool; | ||
this.thread = null; | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
this.runArgs = []; | ||
this.sendArgs = []; | ||
_this.pool = pool; | ||
_this.thread = null; | ||
pool.emit('newJob', this); | ||
_this.runArgs = []; | ||
_this.sendArgs = []; | ||
pool.emit('newJob', _this); | ||
return _this; | ||
} | ||
@@ -73,3 +77,3 @@ | ||
Job.prototype.promise = function promise() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -79,8 +83,8 @@ // Always return a promise | ||
// If the thread isn't set, listen for the threadChanged event | ||
if (!_this.thread) { | ||
_this.once('threadChanged', function () { | ||
resolve(_this.thread.promise()); | ||
if (!_this2.thread) { | ||
_this2.once('threadChanged', function () { | ||
resolve(_this2.thread.promise()); | ||
}); | ||
} else { | ||
resolve(_this.thread.promise()); | ||
resolve(_this2.thread.promise()); | ||
} | ||
@@ -91,6 +95,5 @@ }); | ||
return Job; | ||
})(_eventemitter32['default']); | ||
}(_eventemitter2.default); | ||
exports['default'] = Job; | ||
module.exports = exports['default']; | ||
exports.default = Job; | ||
//# sourceMappingURL=job.js.map |
@@ -5,12 +5,6 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _eventemitter = require('eventemitter3'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _eventemitter3 = require('eventemitter3'); | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
var _job = require('./job'); | ||
@@ -26,22 +20,30 @@ | ||
var Pool = (function (_EventEmitter) { | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Pool = function (_EventEmitter) { | ||
_inherits(Pool, _EventEmitter); | ||
function Pool(threads) { | ||
var _this = this; | ||
_classCallCheck(this, Pool); | ||
_EventEmitter.call(this); | ||
this.threads = Pool.spawn(threads || _defaults2['default'].pool.size); | ||
this.idleThreads = this.threads.slice(); | ||
this.jobQueue = []; | ||
this.runArgs = []; | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
this.on('newJob', function (job) { | ||
_this.threads = Pool.spawn(threads || _defaults2.default.pool.size); | ||
_this.idleThreads = _this.threads.slice(); | ||
_this.jobQueue = []; | ||
_this.runArgs = []; | ||
_this.on('newJob', function (job) { | ||
return _this.handleNewJob(job); | ||
}); | ||
this.on('threadAvailable', function () { | ||
_this.on('threadAvailable', function () { | ||
return _this.dequeue(); | ||
}); | ||
return _this; | ||
} | ||
@@ -63,3 +65,3 @@ | ||
var job = new _job2['default'](this); | ||
var job = new _job2.default(this); | ||
job.run.apply(job, this.runArgs); | ||
@@ -145,6 +147,7 @@ return job.send.apply(job, arguments); | ||
return Pool; | ||
})(_eventemitter32['default']); | ||
}(_eventemitter2.default); | ||
exports['default'] = Pool; | ||
exports.default = Pool; | ||
Pool.spawn = function (threadCount) { | ||
@@ -154,3 +157,3 @@ var threads = []; | ||
for (var threadIndex = 0; threadIndex < threadCount; threadIndex++) { | ||
threads.push(_.spawn()); | ||
threads.push((0, _.spawn)()); | ||
} | ||
@@ -160,3 +163,2 @@ | ||
}; | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=pool.js.map |
@@ -5,4 +5,2 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _slaveCode = require('./slave-code'); | ||
@@ -12,10 +10,12 @@ | ||
var slaveCodeDataUri = 'data:text/javascript;charset=utf-8,' + encodeURI(_slaveCode2['default']); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var slaveCodeDataUri = 'data:text/javascript;charset=utf-8,' + encodeURI(_slaveCode2.default); | ||
var createBlobURL = window.createBlobURL || window.createObjectURL; | ||
if (!createBlobURL) { | ||
var _URL = window.URL || window.webkitURL; | ||
var URL = window.URL || window.webkitURL; | ||
if (_URL) { | ||
createBlobURL = _URL.createObjectURL; | ||
if (URL) { | ||
createBlobURL = URL.createObjectURL; | ||
} else { | ||
@@ -28,11 +28,10 @@ throw new Error('No Blob creation implementation found.'); | ||
var blobBuilder = new window.BlobBuilder(); | ||
blobBuilder.append(_slaveCode2['default']); | ||
blobBuilder.append(_slaveCode2.default); | ||
slaveCodeDataUri = createBlobURL(blobBuilder.getBlob()); | ||
} else if (typeof window.Blob === 'function' && typeof createBlobURL === 'function') { | ||
var blob = new window.Blob([_slaveCode2['default']], { type: 'text/javascript' }); | ||
var blob = new window.Blob([_slaveCode2.default], { type: 'text/javascript' }); | ||
slaveCodeDataUri = createBlobURL(blob); | ||
} | ||
exports['default'] = slaveCodeDataUri; | ||
module.exports = exports['default']; | ||
exports.default = slaveCodeDataUri; | ||
//# sourceMappingURL=slave-code-uri.js.map |
@@ -5,12 +5,8 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _eventemitter = require('eventemitter3'); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
var _eventemitter3 = require('eventemitter3'); | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
var _slaveCodeUri = require('./slave-code-uri'); | ||
@@ -22,3 +18,11 @@ | ||
if (typeof window.Worker !== 'object' && typeof window.Worker !== 'function') { | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
if (_typeof(window.Worker) !== 'object' && typeof window.Worker !== 'function') { | ||
throw new Error('Browser does not support web workers!'); | ||
@@ -38,3 +42,3 @@ } | ||
function prependScriptUrl(scriptUrl) { | ||
var prefix = _config.getConfig().basepath.web; | ||
var prefix = (0, _config.getConfig)().basepath.web; | ||
return prefix ? joinPaths(prefix, scriptUrl) : scriptUrl; | ||
@@ -59,31 +63,32 @@ } | ||
} else if (error.message && error.filename && error.lineno) { | ||
var fileName = error.filename.match(/^data:text\/javascript/) && error.filename.length > 50 ? error.filename.substr(0, 50) + '...' : error.filename; | ||
console.error(error.message + ' @' + fileName + ':' + error.lineno); // eslint-disable-line no-console | ||
} else { | ||
console.error(error); // eslint-disable-line no-console | ||
} | ||
var fileName = error.filename.match(/^data:text\/javascript/) && error.filename.length > 50 ? error.filename.substr(0, 50) + '...' : error.filename; | ||
console.error(error.message + ' @' + fileName + ':' + error.lineno); // eslint-disable-line no-console | ||
} else { | ||
console.error(error); // eslint-disable-line no-console | ||
} | ||
} | ||
var Worker = (function (_EventEmitter) { | ||
var Worker = function (_EventEmitter) { | ||
_inherits(Worker, _EventEmitter); | ||
function Worker() { | ||
var initialScript = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var importScripts = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var initialScript = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var importScripts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
_classCallCheck(this, Worker); | ||
_EventEmitter.call(this); | ||
// used by `run()` to decide if the worker must be re-initialized | ||
this.currentRunnable = null; | ||
this.currentImportScripts = []; | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
this.initWorker(); | ||
this.worker.addEventListener('message', this.handleMessage.bind(this)); | ||
this.worker.addEventListener('error', this.handleError.bind(this)); | ||
_this.currentRunnable = null; | ||
_this.currentImportScripts = []; | ||
_this.initWorker(); | ||
_this.worker.addEventListener('message', _this.handleMessage.bind(_this)); | ||
_this.worker.addEventListener('error', _this.handleError.bind(_this)); | ||
if (initialScript) { | ||
this.run(initialScript, importScripts); | ||
_this.run(initialScript, importScripts); | ||
} | ||
return _this; | ||
} | ||
@@ -93,8 +98,8 @@ | ||
try { | ||
this.worker = new window.Worker(_slaveCodeUri2['default']); | ||
this.worker = new window.Worker(_slaveCodeUri2.default); | ||
} catch (error) { | ||
var slaveScriptUrl = _config.getConfig().fallback.slaveScriptUrl; | ||
var slaveScriptUrl = (0, _config.getConfig)().fallback.slaveScriptUrl; | ||
if (slaveScriptUrl) { | ||
// try using the slave script file instead of the data URI | ||
this.worker = new window.Worker(_slaveCodeUri2['default']); | ||
this.worker = new window.Worker(_slaveCodeUri2.default); | ||
} else { | ||
@@ -108,3 +113,3 @@ // re-throw | ||
Worker.prototype.run = function run(toRun) { | ||
var importScripts = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var importScripts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
@@ -153,3 +158,3 @@ if (this.alreadyInitializedToRun(toRun, importScripts)) { | ||
Worker.prototype.send = function send(param) { | ||
var transferables = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var transferables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
@@ -170,6 +175,17 @@ this.worker.postMessage({ | ||
Worker.prototype.promise = function promise() { | ||
var _this = this; | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.once('message', resolve).once('error', reject); | ||
var resolved = void 0, | ||
rejected = void 0; | ||
resolved = function resolved(result) { | ||
_this2.removeListener('error', rejected); | ||
resolve(result); | ||
}; | ||
rejected = function rejected(err) { | ||
_this2.removeListener('message', resolved); | ||
reject(err); | ||
}; | ||
_this2.once('message', resolved).once('error', rejected); | ||
}); | ||
@@ -214,6 +230,5 @@ }; | ||
return Worker; | ||
})(_eventemitter32['default']); | ||
}(_eventemitter2.default); | ||
exports['default'] = Worker; | ||
module.exports = exports['default']; | ||
exports.default = Worker; | ||
//# sourceMappingURL=worker.js.map |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/*eslint-env node*/ | ||
@@ -8,4 +10,2 @@ /* | ||
'use strict'; | ||
if (typeof process !== 'undefined' && 'pid' in process) { | ||
@@ -12,0 +12,0 @@ module.exports = require('./worker.node/worker'); |
@@ -0,5 +1,5 @@ | ||
'use strict'; | ||
// not using ES6 import/export syntax, since we need to require() in a handler | ||
// what the ES6 syntax does not permit | ||
'use strict'; | ||
var vm = require('vm'); | ||
@@ -6,0 +6,0 @@ |
@@ -5,8 +5,2 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _child_process = require('child_process'); | ||
@@ -20,26 +14,35 @@ | ||
var _eventemitter3 = require('eventemitter3'); | ||
var _eventemitter = require('eventemitter3'); | ||
var _eventemitter32 = _interopRequireDefault(_eventemitter3); | ||
var _eventemitter2 = _interopRequireDefault(_eventemitter); | ||
var _config = require('../config'); | ||
var Worker = (function (_EventEmitter) { | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Worker = function (_EventEmitter) { | ||
_inherits(Worker, _EventEmitter); | ||
function Worker(initialRunnable) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck(this, Worker); | ||
_EventEmitter.call(this); | ||
var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); | ||
this.slave = _child_process2['default'].fork(_path2['default'].join(__dirname, 'slave.js'), [], options); | ||
this.slave.on('message', this.handleMessage.bind(this)); | ||
this.slave.on('error', this.handleError.bind(this)); | ||
this.slave.on('exit', this.emit.bind(this, 'exit')); | ||
_this.slave = _child_process2.default.fork(_path2.default.join(__dirname, 'slave.js'), [], options); | ||
_this.slave.on('message', _this.handleMessage.bind(_this)); | ||
_this.slave.on('error', _this.handleError.bind(_this)); | ||
_this.slave.on('exit', _this.emit.bind(_this, 'exit')); | ||
if (initialRunnable) { | ||
this.run(initialRunnable); | ||
_this.run(initialRunnable); | ||
} | ||
return _this; | ||
} | ||
@@ -68,3 +71,3 @@ | ||
var prefixedScriptPath = _path2['default'].join(_config.getConfig().basepath.node, script); | ||
var prefixedScriptPath = _path2.default.join((0, _config.getConfig)().basepath.node, script); | ||
@@ -74,3 +77,3 @@ // attention: single script for node, array for browser | ||
initByScript: true, | ||
script: _path2['default'].resolve(prefixedScriptPath) | ||
script: _path2.default.resolve(prefixedScriptPath) | ||
}); | ||
@@ -93,6 +96,17 @@ }; | ||
Worker.prototype.promise = function promise() { | ||
var _this = this; | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.once('message', resolve).once('error', reject); | ||
var resolved = void 0, | ||
rejected = void 0; | ||
resolved = function resolved(result) { | ||
_this2.removeListener('error', rejected); | ||
resolve(result); | ||
}; | ||
rejected = function rejected(err) { | ||
_this2.removeListener('message', resolved); | ||
reject(err); | ||
}; | ||
_this2.once('message', resolved).once('error', rejected); | ||
}); | ||
@@ -127,6 +141,5 @@ }; | ||
return Worker; | ||
})(_eventemitter32['default']); | ||
}(_eventemitter2.default); | ||
exports['default'] = Worker; | ||
module.exports = exports['default']; | ||
exports.default = Worker; | ||
//# sourceMappingURL=worker.js.map |
{ | ||
"name": "threads", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"keywords": [ | ||
@@ -29,24 +29,33 @@ "threads", | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"es2015", | ||
"es2015-loose" | ||
] | ||
}, | ||
"devDependencies": { | ||
"async": "^1.4.2", | ||
"browserify": "^9.0.8", | ||
"codeclimate-test-reporter": "^0.1.1", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-es2015-loose": "^8.0.0", | ||
"browserify": "^13.1.1", | ||
"codeclimate-test-reporter": "^0.4.0", | ||
"coveralls": "^2.11.4", | ||
"expect.js": "^0.3.1", | ||
"gulp": "^3.8.11", | ||
"gulp-babel": "^5.2.0", | ||
"gulp-babel": "^6.1.2", | ||
"gulp-concat": "^2.5.2", | ||
"gulp-eslint": "^0.9.0", | ||
"gulp-mocha": "^2.1.3", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-mocha": "^3.0.1", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-sourcemaps": "^1.5.2", | ||
"gulp-uglify": "^1.2.0", | ||
"gulp-uglify": "^2.0.0", | ||
"istanbul": "^0.4.0", | ||
"karma": "^0.13.9", | ||
"karma": "^1.3.0", | ||
"karma-browserify": "^4.3.0", | ||
"karma-chrome-launcher": "^0.2.0", | ||
"karma-chrome-launcher": "^2.0.0", | ||
"karma-expect": "^1.1.0", | ||
"karma-firefox-launcher": "^0.1.6", | ||
"karma-mocha": "^0.2.0", | ||
"karma-phantomjs-launcher": "^0.2.1", | ||
"karma-firefox-launcher": "^1.0.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-phantomjs-launcher": "^1.0.2", | ||
"mocha": "^3.1.2", | ||
"phantomjs": "^1.9.18", | ||
@@ -58,3 +67,3 @@ "sinon": "^1.16.1", | ||
"dependencies": { | ||
"eventemitter3": "^1.1.1", | ||
"eventemitter3": "^2.0.2", | ||
"native-promise-only": "^0.8.1" | ||
@@ -61,0 +70,0 @@ }, |
@@ -344,25 +344,7 @@ # threads.js | ||
## Changelog | ||
## Change log | ||
### 0.7.1 | ||
See [CHANGELOG.md](./CHANGELOG.md). | ||
`Pool.prototype.run()` now accepts more than one parameter. See [#31](https://github.com/andywer/threads.js/pull/31). | ||
Credit goes to https://github.com/DatenMetzgerX | ||
### 0.7.0 | ||
Fixes a critical issue that prevented thread pools from running all jobs. | ||
Also brings some major performance improvements for browser (web worker) - based setups. | ||
### 0.6.1 | ||
Added alias for threads: Event `done` as alias for `message`. Updated README example code. | ||
Credit goes to https://github.com/andrakis | ||
### 0.6.0 | ||
Fixes promise and async issues. `Job.clone()` has been dropped. | ||
Credit goes to https://github.com/maysale01 | ||
## License | ||
@@ -369,0 +351,0 @@ |
@@ -141,5 +141,15 @@ import EventEmitter from 'eventemitter3'; | ||
return new Promise((resolve, reject) => { | ||
let resolved, rejected; | ||
resolved = (result) => { | ||
this.removeListener('error', rejected); | ||
resolve(result); | ||
}; | ||
rejected = (err) => { | ||
this.removeListener('message', resolved); | ||
reject(err); | ||
}; | ||
this | ||
.once('message', resolve) | ||
.once('error', reject); | ||
.once('message', resolved) | ||
.once('error', rejected); | ||
}); | ||
@@ -146,0 +156,0 @@ } |
@@ -65,5 +65,15 @@ import child from 'child_process'; | ||
return new Promise((resolve, reject) => { | ||
let resolved, rejected; | ||
resolved = (result) => { | ||
this.removeListener('error', rejected); | ||
resolve(result); | ||
}; | ||
rejected = (err) => { | ||
this.removeListener('message', resolved); | ||
reject(err); | ||
}; | ||
this | ||
.once('message', resolve) | ||
.once('error', reject); | ||
.once('message', resolved) | ||
.once('error', rejected); | ||
}); | ||
@@ -70,0 +80,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
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
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170654
28
58
2569
355
+ Addedeventemitter3@2.0.3(transitive)
- Removedeventemitter3@1.2.0(transitive)
Updatedeventemitter3@^2.0.2