workerpool
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -7,4 +7,4 @@ /** | ||
* | ||
* @version 0.1.0 | ||
* @date 2014-05-07 | ||
* @version 0.2.0 | ||
* @date 2014-05-14 | ||
* | ||
@@ -26,4 +26,3 @@ * @license | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.workerpool=e():t.workerpool=e()}(this,function(){return function(t){function e(i){if(r[i])return r[i].exports;var n=r[i]={exports:{},id:i,loaded:!1};return t[i].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){e.pool=function(t){var e=r(1);return new e(t)},e.worker=function i(t){var e=r(2);if("browser"==e){var n=new Blob([r(3)],{type:"text/javascript"}),o=window.URL.createObjectURL(n);importScripts(o)}else var i=r(4);i.add(t)}},function(t,e,r){function i(t,e){if("string"==typeof t?this.script=t||null:(this.script=null,e=t),e&&"maxWorkers"in e){if(!n(e.maxWorkers)||!o(e.maxWorkers)||e.maxWorkers<1)throw new TypeError("Option maxWorkers must be a positive integer number");this.maxWorkers=e.maxWorkers}else{var i=r(2),s="browser"==i?4:r(6).cpus().length;this.maxWorkers=Math.max(s-1,1)}this.workers=[],this.tasks=[]}function n(t){return"number"==typeof t}function o(t){return Math.round(t)==t}var s=r(8),a=r(5);i.prototype.run=function(t,e){if("function"!=typeof t)throw new TypeError('Function expected as argument "fn"');if(e&&!Array.isArray(e))throw new TypeError('Array expected as argument "args"');return this.exec("run",[String(t),e])},i.prototype.exec=function(t,e){var r=this;return new s(function(i,n){r.tasks.push({method:t,params:e,resolve:i,reject:n}),r._next()})},i.prototype.proxy=function(){var t=this;return this.exec("methods").then(function(e){var r={};return e.forEach(function(e){r[e]=function(){return t.exec(e,Array.prototype.slice.call(arguments))}}),r})},i.prototype._next=function(){if(this.tasks.length>0){var t=this._getWorker();if(t){var e=this,r=this.tasks.shift();t.exec(r.method,r.params).then(function(t){r.resolve(t),e._next()}).catch(function(i){r.reject(i),t.terminated&&e._removeWorker(t),e._next()})}}},i.prototype._getWorker=function(){for(var t=0,e=this.workers.length;e>t;t++){var r=this.workers[t];if(!r.busy())return r}return this.workers.length<this.maxWorkers?(r=new a(this.script),this.workers.push(r),r):null},i.prototype._removeWorker=function(t){t.terminate();var e=this.workers.indexOf(t);-1!=e&&this.workers.splice(e,1)},i.prototype.clear=function(t){this.workers.forEach(function(e){e.terminate(t)}),this.workers=[]},t.exports=i},function(t){t.exports="undefined"!=typeof window?"browser":"node"},function(t){t.exports='function isPromise(e){return e&&"function"==typeof e.then&&"function"==typeof e.catch}var worker={};if("undefined"!=typeof self&&"function"==typeof postMessage&&"function"==typeof addEventListener)worker.on=function(e,r){addEventListener(e,function(e){r(e.data)})},worker.send=function(e){postMessage(e)};else{if("undefined"==typeof process)throw new Error("Script must be executed as a worker");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}worker.methods={},worker.methods.run=function run(fn,args){var f=eval("("+fn+")");return f.apply(f,args)},worker.methods.methods=function(){return Object.keys(worker.methods)},worker.on("message",function(e){try{var r=worker.methods[e.method];if(!r)throw new Error(\'Unknown method "\'+e.method+\'"\');var o=r.apply(r,e.params);isPromise(o)?o.then(function(r){worker.send({id:e.id,result:r,error:null})}).catch(function(r){worker.send({id:e.id,result:null,error:r.toString()})}):worker.send({id:e.id,result:o,error:null})}catch(n){worker.send({id:e.id,result:null,error:n.toString()})}}),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r])},"undefined"!=typeof exports&&(exports.add=worker.register);'},function(module,exports,__webpack_require__){(function(process){function isPromise(t){return t&&"function"==typeof t.then&&"function"==typeof t.catch}var worker={};if("undefined"!=typeof self&&"function"==typeof postMessage&&"function"==typeof addEventListener)worker.on=function(t,e){addEventListener(t,function(t){e(t.data)})},worker.send=function(t){postMessage(t)};else{if("undefined"==typeof process)throw new Error("Script must be executed as a worker");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}worker.methods={},worker.methods.run=function run(fn,args){var f=eval("("+fn+")");return f.apply(f,args)},worker.methods.methods=function(){return Object.keys(worker.methods)},worker.on("message",function(t){try{var e=worker.methods[t.method];if(!e)throw new Error('Unknown method "'+t.method+'"');var r=e.apply(e,t.params);isPromise(r)?r.then(function(e){worker.send({id:t.id,result:e,error:null})}).catch(function(e){worker.send({id:t.id,result:null,error:e.toString()})}):worker.send({id:t.id,result:r,error:null})}catch(i){worker.send({id:t.id,result:null,error:i.toString()})}}),worker.register=function(t){if(t)for(var e in t)t.hasOwnProperty(e)&&(worker.methods[e]=t[e])},exports.add=worker.register}).call(exports,__webpack_require__(7))},function(t,e,r){(function(e){function i(){if("browser"==a){if("undefined"==typeof Blob)throw new Error("Blob not supported by the browser");if(!window.URL||"function"!=typeof window.URL.createObjectURL)throw new Error("URL.createObjectURL not supported by the browser");var t=new Blob([r(3)],{type:"text/javascript"});return window.URL.createObjectURL(t)}return e+"/worker.js"}function n(t){function e(t){r.terminated=!0;for(var e in r.processing)r.processing.hasOwnProperty(e)&&r.processing[e].reject(t);r.processing={}}if(this.script=t||i(),"browser"==a){if("function"!=typeof Worker)throw new Error("Web workers not supported by the browser");this.worker=new Worker(this.script),this.worker.on=function(t,e){this.addEventListener(t,function(t){e(t.data)})},this.worker.send=function(t){this.postMessage(t)}}else this.worker=s.fork(this.script);var r=this;this.worker.on("message",function(t){var e=t.id,i=r.processing[e];if(i){delete r.processing[e];try{t.error?i.reject(t.error):i.resolve(t.result)}catch(n){}r.terminating&&r.terminate()}}),this.worker.on("error",e),this.worker.on("exit",function(){var t=new Error("Worker terminated unexpectedly");e(t)}),this.processing={},this.terminating=!1,this.terminated=!1,this.lastId=0}var o=r(8),s=r(9),a=r(2);n.prototype.methods=function(){return this.exec("methods")},n.prototype.exec=function(t,e){var r=this;return new o(function(i,n){var o=++r.lastId;r.processing[o]={id:o,resolve:i,reject:n};var s={id:o,method:t,params:e};r.worker.send(s)})},n.prototype.busy=function(){return Object.keys(this.processing).length>0},n.prototype.terminate=function(t){if(t){for(var e in this.processing)this.processing.hasOwnProperty(e)&&this.processing[e].reject(new Error("Worker terminated"));this.processing={}}if(this.busy())this.terminating=!0;else{if(this.worker){if("function"==typeof this.worker.kill)this.worker.kill();else{if("function"!=typeof this.worker.terminate)throw new Error("Failed to terminate worker");this.worker.terminate()}this.worker=null}this.terminating=!1,this.terminated=!0}},t.exports=n}).call(e,"/")},function(t,e){e.endianness=function(){return"LE"},e.hostname=function(){return"undefined"!=typeof location?location.hostname:""},e.loadavg=function(){return[]},e.uptime=function(){return 0},e.freemem=function(){return Number.MAX_VALUE},e.totalmem=function(){return Number.MAX_VALUE},e.cpus=function(){return[]},e.type=function(){return"Browser"},e.release=function(){return"undefined"!=typeof navigator?navigator.appVersion:""},e.networkInterfaces=e.getNetworkInterfaces=function(){return{}},e.arch=function(){return"javascript"},e.platform=function(){return"browser"},e.tmpdir=e.tmpDir=function(){return"/tmp"},e.EOL="\n"},function(t){function e(){}var r=t.exports={};r.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var r=[];return window.addEventListener("message",function(t){var e=t.source;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),r.length>0)){var i=r.shift();i()}},!0),function(t){r.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=e,r.once=e,r.off=e,r.emit=e,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")}},function(t,e,r){"use strict";var i=r(10)();t.exports=i},function(){},function(t,e,r){(function(e){"use strict";t.exports=function(){function t(t){return void 0===t?!1:t instanceof n}function i(t,e){return t instanceof d?e>=0:!1}function n(t){if("function"!=typeof t)throw new x("the promise constructor requires a resolver function");if(this.constructor!==n)throw new x("the promise constructor cannot be invoked directly");this._bitField=0,this._fulfillmentHandler0=void 0,this._rejectionHandler0=void 0,this._promise0=void 0,this._receiver0=void 0,this._settledValue=void 0,this._boundTo=void 0,t!==f&&this._resolveFromResolver(t)}function o(t,e){return s(t,d,e===!0&&t._isBound()?t._boundTo:void 0).promise()}function s(e,r,i){var o=null;return m(e)?o=e:(o=n._cast(e,void 0),o!==e?o._setBoundTo(i):t(o)||(o=null)),null!==o?new r(o,i):{promise:function(){return U("expecting an array, a promise or a thenable")}}}var a=r(11),c=r(12),u=r(13),l=r(14),f=function(){},h={},p={e:null},d=r(15)(n,f),_=r(16)(),v=r(17)(p),y=r(18),m=c.isArray,w=c.errorObj,g=c.tryCatch1,b=c.tryCatch2,k=c.tryCatchApply,j=l.RangeError,x=l.TypeError,T=l.CancellationError,E=l.TimeoutError,F=l.RejectionError,P=l.originatesFromRejection,R=l.markAsOriginatingFromRejection,A=l.canAttach,C=c.thrower,U=r(19)(n),O=function(){return new x("circular promise resolution chain")};n.prototype.bind=function(t){var e=new n(f);return e._setTrace(this),e._follow(this),e._setBoundTo(t),this._cancellable()&&(e._setCancellable(),e._cancellationParent=this),e},n.prototype.toString=function(){return"[object Promise]"},n.prototype.caught=n.prototype["catch"]=function(t){var e=arguments.length;if(e>1){var r,i=new Array(e-1),n=0;for(r=0;e-1>r;++r){var o=arguments[r];if("function"!=typeof o){var s=new x("A catch filter must be an error constructor or a filter function");return this._attachExtraTrace(s),void u.invoke(this._reject,this,s)}i[n++]=o}i.length=n,t=arguments[r],this._resetTrace();var a=new v(i,t,this);return this._then(void 0,a.doFilter,void 0,a,void 0)}return this._then(void 0,t,void 0,void 0,void 0)},n.prototype.then=function(t,e,r){return this._then(t,e,r,void 0,void 0)},n.prototype.done=function(t,e,r){var i=this._then(t,e,r,void 0,void 0);i._setIsFinal()},n.prototype.spread=function(t,e){return this._then(t,e,void 0,h,void 0)},n.prototype.isCancellable=function(){return!this.isResolved()&&this._cancellable()},n.prototype.toJSON=function(){var t={isFulfilled:!1,isRejected:!1,fulfillmentValue:void 0,rejectionReason:void 0};return this.isFulfilled()?(t.fulfillmentValue=this._settledValue,t.isFulfilled=!0):this.isRejected()&&(t.rejectionReason=this._settledValue,t.isRejected=!0),t},n.prototype.all=function(){return o(this,!0)},n.is=t,n.all=function(t){return o(t,!1)},n.join=function(){for(var t=arguments.length,e=new Array(t),r=0;t>r;++r)e[r]=arguments[r];return s(e,d,void 0).promise()},n.resolve=n.fulfilled=function(t){var e=new n(f);return e._setTrace(void 0),e._tryFollow(t)?e:(e._cleanValues(),e._setFulfilled(),e._settledValue=t,e)},n.reject=n.rejected=function(t){var e=new n(f);if(e._setTrace(void 0),R(t),e._cleanValues(),e._setRejected(),e._settledValue=t,!A(t)){var r=new Error(t+"");e._setCarriedStackTrace(r)}return e._ensurePossibleRejectionHandled(),e},n.prototype.error=function(t){return this.caught(P,t)},n.prototype._resolveFromSyncValue=function(t){if(t===w)this._cleanValues(),this._setRejected(),this._settledValue=t.e,this._ensurePossibleRejectionHandled();else{var e=n._cast(t,void 0);e instanceof n?this._follow(e):(this._cleanValues(),this._setFulfilled(),this._settledValue=t)}},n.method=function(t){if("function"!=typeof t)throw new x("fn must be a function");return function(){var e;switch(arguments.length){case 0:e=g(t,this,void 0);break;case 1:e=g(t,this,arguments[0]);break;case 2:e=b(t,this,arguments[0],arguments[1]);break;default:for(var r=arguments.length,i=new Array(r),o=0;r>o;++o)i[o]=arguments[o];e=k(t,i,this)}var s=new n(f);return s._setTrace(void 0),s._resolveFromSyncValue(e),s}},n.attempt=n["try"]=function(t,e,r){if("function"!=typeof t)return U("fn must be a function");var i=m(e)?k(t,e,r):g(t,r,e),o=new n(f);return o._setTrace(void 0),o._resolveFromSyncValue(i),o},n.defer=n.pending=function(){var t=new n(f);return t._setTrace(void 0),new y(t)},n.bind=function(t){var e=new n(f);return e._setTrace(void 0),e._setFulfilled(),e._setBoundTo(t),e},n.cast=function(t){var e=n._cast(t,void 0);return e instanceof n?e:n.resolve(e)},n.onPossiblyUnhandledRejection=function(t){_.possiblyUnhandledRejection="function"==typeof t?t:void 0};var S;n.onUnhandledRejectionHandled=function(t){S="function"==typeof t?t:void 0};var B=!1||!("undefined"==typeof e||"string"!=typeof e.execPath||"object"!=typeof e.env||!e.env.BLUEBIRD_DEBUG&&"development"!==e.env.NODE_ENV);n.longStackTraces=function(){if(u.haveItemsQueued()&&B===!1)throw new Error("cannot enable long stack traces after promises have been created");B=_.isSupported()},n.hasLongStackTraces=function(){return B&&_.isSupported()},n.prototype._setProxyHandlers=function(t,e){var r=this._length();if(r>=524282&&(r=0,this._setLength(0)),0===r)this._promise0=e,this._receiver0=t;else{var i=r-5;this[i+3]=e,this[i+4]=t,this[i+0]=this[i+1]=this[i+2]=void 0}this._setLength(r+5)},n.prototype._proxyPromiseArray=function(t,e){this._setProxyHandlers(t,e)},n.prototype._proxyPromise=function(t){t._setProxied(),this._setProxyHandlers(t,-1)},n.prototype._then=function(t,e,r,i,o){var s=void 0!==o,a=s?o:new n(f);if(B&&!s){var c=this._peekContext()===this._traceParent;a._traceParent=c?this._traceParent:this,a._setTrace(this)}!s&&this._isBound()&&a._setBoundTo(this._boundTo);var l=this._addCallbacks(t,e,r,a,i);return!s&&this._cancellable()&&(a._setCancellable(),a._cancellationParent=this),this.isResolved()&&u.invoke(this._queueSettleAt,this,l),a},n.prototype._length=function(){return 524287&this._bitField},n.prototype._isFollowingOrFulfilledOrRejected=function(){return(939524096&this._bitField)>0},n.prototype._isFollowing=function(){return 536870912===(536870912&this._bitField)},n.prototype._setLength=function(t){this._bitField=-524288&this._bitField|524287&t},n.prototype._setFulfilled=function(){this._bitField=268435456|this._bitField},n.prototype._setRejected=function(){this._bitField=134217728|this._bitField},n.prototype._setFollowing=function(){this._bitField=536870912|this._bitField},n.prototype._setIsFinal=function(){this._bitField=33554432|this._bitField},n.prototype._isFinal=function(){return(33554432&this._bitField)>0},n.prototype._cancellable=function(){return(67108864&this._bitField)>0},n.prototype._setCancellable=function(){this._bitField=67108864|this._bitField},n.prototype._unsetCancellable=function(){this._bitField=-67108865&this._bitField},n.prototype._setRejectionIsUnhandled=function(){this._bitField=2097152|this._bitField},n.prototype._unsetRejectionIsUnhandled=function(){this._bitField=-2097153&this._bitField,this._isUnhandledRejectionNotified()&&(this._unsetUnhandledRejectionIsNotified(),this._notifyUnhandledRejectionIsHandled())},n.prototype._isRejectionUnhandled=function(){return(2097152&this._bitField)>0},n.prototype._setUnhandledRejectionIsNotified=function(){this._bitField=524288|this._bitField},n.prototype._unsetUnhandledRejectionIsNotified=function(){this._bitField=-524289&this._bitField},n.prototype._isUnhandledRejectionNotified=function(){return(524288&this._bitField)>0},n.prototype._setCarriedStackTrace=function(t){this._bitField=1048576|this._bitField,this._fulfillmentHandler0=t},n.prototype._unsetCarriedStackTrace=function(){this._bitField=-1048577&this._bitField,this._fulfillmentHandler0=void 0},n.prototype._isCarryingStackTrace=function(){return(1048576&this._bitField)>0},n.prototype._getCarriedStackTrace=function(){return this._isCarryingStackTrace()?this._fulfillmentHandler0:void 0},n.prototype._receiverAt=function(t){var e;return e=0===t?this._receiver0:this[t+4-5],this._isBound()&&void 0===e?this._boundTo:e},n.prototype._promiseAt=function(t){return 0===t?this._promise0:this[t+3-5]},n.prototype._fulfillmentHandlerAt=function(t){return 0===t?this._fulfillmentHandler0:this[t+0-5]},n.prototype._rejectionHandlerAt=function(t){return 0===t?this._rejectionHandler0:this[t+1-5]},n.prototype._unsetAt=function(t){0===t?(this._rejectionHandler0=this._progressHandler0=this._promise0=this._receiver0=void 0,this._isCarryingStackTrace()||(this._fulfillmentHandler0=void 0)):this[t-5+0]=this[t-5+1]=this[t-5+2]=this[t-5+3]=this[t-5+4]=void 0},n.prototype._resolveFromResolver=function(t){function e(t){i._tryFollow(t)||i._fulfill(t)}function r(t){var e=A(t)?t:new Error(t+"");i._attachExtraTrace(e),R(t),i._reject(t,e===t?void 0:e)}var i=this;this._setTrace(void 0),this._pushContext();var n=b(t,void 0,e,r);if(this._popContext(),void 0!==n&&n===w){var o=n.e,s=A(o)?o:new Error(o+"");i._reject(o,s)}},n.prototype._addCallbacks=function(t,e,r,i,n){var o=this._length();if(o>=524282&&(o=0,this._setLength(0)),0===o)this._promise0=i,void 0!==n&&(this._receiver0=n),"function"!=typeof t||this._isCarryingStackTrace()||(this._fulfillmentHandler0=t),"function"==typeof e&&(this._rejectionHandler0=e),"function"==typeof r&&(this._progressHandler0=r);else{var s=o-5;this[s+3]=i,this[s+4]=n,this[s+0]="function"==typeof t?t:void 0,this[s+1]="function"==typeof e?e:void 0,this[s+2]="function"==typeof r?r:void 0}return this._setLength(o+5),o},n.prototype._setBoundTo=function(t){void 0!==t?(this._bitField=8388608|this._bitField,this._boundTo=t):this._bitField=-8388609&this._bitField},n.prototype._isBound=function(){return 8388608===(8388608&this._bitField)},n.prototype._spreadSlowCase=function(t,e,r,i){var n=s(r,d,i).promise()._then(function(){return t.apply(i,arguments)},void 0,void 0,h,void 0);e._follow(n)},n.prototype._callSpread=function(e,r,i,o){var s=this._isBound()?this._boundTo:void 0;if(m(i))for(var a=0,c=i.length;c>a;++a)if(t(n._cast(i[a],void 0)))return void this._spreadSlowCase(e,r,i,s);return o&&r._pushContext(),k(e,i,s)},n.prototype._callHandler=function(t,e,r,i,n){var o;return e!==h||this.isRejected()?(n&&r._pushContext(),o=g(t,e,i)):o=this._callSpread(t,r,i,n),n&&r._popContext(),o},n.prototype._settlePromiseFromHandler=function(e,r,i,o){if(!t(o))return void e.call(r,i,o);var s=B,a=this._callHandler(e,r,o,i,s);if(!o._isFollowing())if(a===w||a===o||a===p){var c=a===o?O():a.e,u=A(c)?c:new Error(c+"");a!==p&&o._attachExtraTrace(u),o._rejectUnchecked(c,u)}else{var l=n._cast(a,o);if(t(l)){if(l.isRejected()&&!l._isCarryingStackTrace()&&!A(l._settledValue)){var u=new Error(l._settledValue+"");o._attachExtraTrace(u),l._setCarriedStackTrace(u)}o._follow(l),l._cancellable()&&(o._cancellationParent=l,o._setCancellable())}else o._fulfillUnchecked(a)}},n.prototype._follow=function(t){this._setFollowing(),t.isPending()?(t._cancellable()&&(this._cancellationParent=t,this._setCancellable()),t._proxyPromise(this)):t.isFulfilled()?this._fulfillUnchecked(t._settledValue):this._rejectUnchecked(t._settledValue,t._getCarriedStackTrace()),t._isRejectionUnhandled()&&t._unsetRejectionIsUnhandled(),B&&null==t._traceParent&&(t._traceParent=this)},n.prototype._tryFollow=function(e){if(this._isFollowingOrFulfilledOrRejected()||e===this)return!1;var r=n._cast(e,void 0);return t(r)?(this._follow(r),!0):!1},n.prototype._resetTrace=function(){B&&(this._trace=new _(void 0===this._peekContext()))},n.prototype._setTrace=function(t){if(B){var e=this._peekContext();this._traceParent=e;var r=void 0===e;this._trace=void 0!==t&&t._traceParent===e?t._trace:new _(r)}return this},n.prototype._attachExtraTrace=function(t){if(B){var e=this,r=t.stack;r="string"==typeof r?r.split("\n"):[];for(var i=1;null!=e&&null!=e._trace;)r=_.combine(r,e._trace.stack.split("\n")),e=e._traceParent;var n=Error.stackTraceLimit+i,o=r.length;o>n&&(r.length=n),t.stack=r.length<=i?"(No stack trace)":r.join("\n")}},n.prototype._cleanValues=function(){this._cancellable()&&(this._cancellationParent=void 0)},n.prototype._fulfill=function(t){this._isFollowingOrFulfilledOrRejected()||this._fulfillUnchecked(t)},n.prototype._reject=function(t,e){this._isFollowingOrFulfilledOrRejected()||this._rejectUnchecked(t,e)},n.prototype._settlePromiseAt=function(t){var e=this.isFulfilled()?this._fulfillmentHandlerAt(t):this._rejectionHandlerAt(t),r=this._settledValue,o=this._receiverAt(t),s=this._promiseAt(t);if("function"==typeof e)this._settlePromiseFromHandler(e,o,r,s);else{var a=!1,c=this.isFulfilled();void 0!==o&&(o instanceof n&&o._isProxied()?(o._unsetProxied(),c?o._fulfillUnchecked(r):o._rejectUnchecked(r,this._getCarriedStackTrace()),a=!0):i(o,s)&&(c?o._promiseFulfilled(r,s):o._promiseRejected(r,s),a=!0)),a||(c?s._fulfill(r):s._reject(r,this._getCarriedStackTrace()))}t>=256&&this._queueGC()},n.prototype._isProxied=function(){return 4194304===(4194304&this._bitField)},n.prototype._setProxied=function(){this._bitField=4194304|this._bitField},n.prototype._unsetProxied=function(){this._bitField=-4194305&this._bitField},n.prototype._isGcQueued=function(){return-1073741824===(-1073741824&this._bitField)},n.prototype._setGcQueued=function(){this._bitField=-1073741824|this._bitField},n.prototype._unsetGcQueued=function(){this._bitField=1073741823&this._bitField},n.prototype._queueGC=function(){this._isGcQueued()||(this._setGcQueued(),u.invokeLater(this._gc,this,void 0))},n.prototype._gc=function(){var t=this._length();this._unsetAt(0);for(var e=0;t>e;e++)delete this[e];this._setLength(0),this._unsetGcQueued()},n.prototype._queueSettleAt=function(t){this._isRejectionUnhandled()&&this._unsetRejectionIsUnhandled(),u.invoke(this._settlePromiseAt,this,t)},n.prototype._fulfillUnchecked=function(t){if(this.isPending()){if(t===this){var e=O();return this._attachExtraTrace(e),this._rejectUnchecked(e,void 0)}this._cleanValues(),this._setFulfilled(),this._settledValue=t;var r=this._length();r>0&&u.invoke(this._settlePromises,this,r)}},n.prototype._rejectUncheckedCheckError=function(t){var e=A(t)?t:new Error(t+"");this._rejectUnchecked(t,e===t?void 0:e)},n.prototype._rejectUnchecked=function(t,e){if(this.isPending()){if(t===this){var r=O();return this._attachExtraTrace(r),this._rejectUnchecked(r)}if(this._cleanValues(),this._setRejected(),this._settledValue=t,this._isFinal())return void u.invokeLater(C,void 0,void 0===e?t:e);var i=this._length();void 0!==e&&this._setCarriedStackTrace(e),i>0?u.invoke(this._rejectPromises,this,null):this._ensurePossibleRejectionHandled()}},n.prototype._rejectPromises=function(){this._settlePromises(),this._unsetCarriedStackTrace()},n.prototype._settlePromises=function(){for(var t=this._length(),e=0;t>e;e+=5)this._settlePromiseAt(e)},n.prototype._ensurePossibleRejectionHandled=function(){this._setRejectionIsUnhandled(),void 0!==_.possiblyUnhandledRejection&&u.invokeLater(this._notifyUnhandledRejection,this,void 0)},n.prototype._notifyUnhandledRejectionIsHandled=function(){"function"==typeof S&&u.invokeLater(S,void 0,this)},n.prototype._notifyUnhandledRejection=function(){if(this._isRejectionUnhandled()){var t=this._settledValue,e=this._getCarriedStackTrace();this._setUnhandledRejectionIsNotified(),void 0!==e&&(this._unsetCarriedStackTrace(),t=e),"function"==typeof _.possiblyUnhandledRejection&&_.possiblyUnhandledRejection(t,this)}};var V=[];n.prototype._peekContext=function(){var t=V.length-1;return t>=0?V[t]:void 0},n.prototype._pushContext=function(){B&&V.push(this)},n.prototype._popContext=function(){B&&V.pop()};var L=a.Promise;return n.noConflict=function(){return a.Promise===n&&(a.Promise=L),n},_.isSupported()||(n.longStackTraces=function(){},B=!1),n._makeSelfResolutionError=O,r(20)(n,p),r(21)(n),r(22)(n,f),r(23)(n),n.RangeError=j,n.CancellationError=T,n.TimeoutError=E,n.TypeError=x,n.RejectionError=F,c.toFastProperties(n),c.toFastProperties(n.prototype),r(24)(n,f),r(25)(n,s,d),r(26)(n,f),r(27)(n),r(28)(n,s,d,U),r(29)(n,U,f),r(30)(n,d,f,U),r(31)(n),r(32)(n,f),r(33)(n,d),r(34)(n,s,d,U,f),r(35)(n,s,d),r(36)(n,s,d,U),r(37)(n,i),r(38)(n,f),n.prototype=n.prototype,n}}).call(e,r(7))},function(t,e){(function(e){t.exports=function(){if(void 0!==this)return this;try{return e}catch(t){}try{return window}catch(t){}try{return self}catch(t){}}()}).call(e,function(){return this}())},function(t,e,r){"use strict";function i(t){"undefined"!=typeof console&&null!==console&&"function"==typeof console.warn&&console.warn("Bluebird: "+t)}function n(t,e,r){try{return t.call(e,r)}catch(i){return w.e=i,w}}function o(t,e,r,i){try{return t.call(e,r,i)}catch(n){return w.e=n,w}}function s(t,e,r){try{return t.apply(r,e)}catch(i){return w.e=i,w}}function a(t){return"string"==typeof t?t:""+t}function c(t){return null==t||t===!0||t===!1||"string"==typeof t||"number"==typeof t}function u(t){return!c(t)}function l(t){return c(t)?new Error(a(t)):t}function f(t,e){var r,i=t.length,n=new Array(i+1);for(r=0;i>r;++r)n[r]=t[r];return n[r]=e,n}function h(t,e,r){if(c(t))return t;var i={value:r,configurable:!0,enumerable:!1,writable:!0};return v.defineProperty(t,e,i),t}function p(t){throw t}function d(t){function e(){}return e.prototype=t,e}var _=r(11),v=r(39),y=function(){try{var t={};return v.defineProperty(t,"f",{get:function(){return 3}}),3===t.f}catch(e){return!1}}(),m=function(){return"undefined"!=typeof window&&null!==window&&"undefined"!=typeof window.document&&"undefined"!=typeof navigator&&null!==navigator&&"string"==typeof navigator.appName&&window===_?!1:!0}(),w={e:{}},g=function(t,e){function r(){this.constructor=t,this.constructor$=e;for(var r in e.prototype)i.call(e.prototype,r)&&"$"!==r.charAt(r.length-1)&&(this[r+"$"]=e.prototype[r])}var i={}.hasOwnProperty;return r.prototype=e.prototype,t.prototype=new r,t.prototype},b=function(){return"string"!==this}.call("string"),k={thrower:p,isArray:v.isArray,haveGetters:y,notEnumerableProp:h,isPrimitive:c,isObject:u,canEvaluate:m,deprecated:i,errorObj:w,tryCatch1:n,tryCatch2:o,tryCatchApply:s,inherits:g,withAppended:f,asString:a,maybeWrapAsError:l,wrapsPrimitiveReceiver:b,toFastProperties:d};t.exports=k},function(t,e,r){"use strict";function i(){this._isTickUsed=!1,this._length=0,this._lateBuffer=new o,this._functionBuffer=new o(75e3);var t=this;this.consumeFunctionBuffer=function(){t._consumeFunctionBuffer()}}var n=r(40),o=r(41),s=r(12).errorObj,a=r(12).tryCatch1,c=r(11).process;i.prototype.haveItemsQueued=function(){return this._length>0},i.prototype.invokeLater=function(t,e,r){void 0===c||null==c.domain||t.domain||(t=c.domain.bind(t)),this._lateBuffer.push(t,e,r),this._queueTick()},i.prototype.invoke=function(t,e,r){void 0===c||null==c.domain||t.domain||(t=c.domain.bind(t));var i=this._functionBuffer;i.push(t,e,r),this._length=i.length(),this._queueTick()},i.prototype._consumeFunctionBuffer=function(){for(var t=this._functionBuffer;t.length()>0;){var e=t.shift(),r=t.shift(),i=t.shift();e.call(r,i)}this._reset(),this._consumeLateBuffer()},i.prototype._consumeLateBuffer=function(){for(var t=this._lateBuffer;t.length()>0;){var e=t.shift(),r=t.shift(),i=t.shift(),n=a(e,r,i);if(n===s){if(this._queueTick(),null==e.domain)throw n.e;e.domain.emit("error",n.e)}}},i.prototype._queueTick=function(){this._isTickUsed||(n(this.consumeFunctionBuffer),this._isTickUsed=!0)},i.prototype._reset=function(){this._isTickUsed=!1,this._length=0},t.exports=new i},function(t,e,r){"use strict";function i(t){try{p(t,"isAsync",!0)}catch(e){}}function n(t){return null==t?!1:t instanceof c||t.isAsync===!0}function o(t){return t instanceof d}function s(t){return o(t)}function a(t,e){function r(i){return this instanceof r?(this.message="string"==typeof i?i:e,this.name=t,void(d.captureStackTrace&&d.captureStackTrace(this,this.constructor))):new r(i)}return h(r,d),r}function c(t){this.name="RejectionError",this.message=t,this.cause=t,this.isAsync=!0,t instanceof d?(this.message=t.message,this.stack=t.stack):d.captureStackTrace&&d.captureStackTrace(this,this.constructor)}var u=r(11),l=r(39).freeze,f=r(12),h=f.inherits,p=f.notEnumerableProp,d=u.Error,_=u.TypeError;"function"!=typeof _&&(_=a("TypeError","type error"));var v=u.RangeError;"function"!=typeof v&&(v=a("RangeError","range error"));var y=a("CancellationError","cancellation error"),m=a("TimeoutError","timeout error");h(c,d);var w="__BluebirdErrorTypes__",g=u[w];g||(g=l({CancellationError:y,TimeoutError:m,RejectionError:c}),p(u,w,g)),t.exports={Error:d,TypeError:_,RangeError:v,CancellationError:g.CancellationError,RejectionError:g.RejectionError,TimeoutError:g.TimeoutError,originatesFromRejection:n,markAsOriginatingFromRejection:i,canAttach:s}},function(t,e,r){"use strict";t.exports=function(t,e){function i(t){switch(t){case-1:return void 0;case-2:return[];case-3:return{}}}function n(r,i){var n=this._promise=new t(e),o=void 0;r instanceof t&&(o=r,r._cancellable()&&(n._setCancellable(),n._cancellationParent=r),r._isBound()&&n._setBoundTo(i)),n._setTrace(o),this._values=r,this._length=0,this._totalResolved=0,this._init(void 0,-2)}var o=r(14).canAttach,s=r(12),a=r(13),c={}.hasOwnProperty,u=s.isArray;return n.PropertiesPromiseArray=function(){},n.prototype.length=function(){return this._length},n.prototype.promise=function(){return this._promise},n.prototype._init=function(e,r){var o=this._values;if(o instanceof t){if(!o.isFulfilled())return o.isPending()?void o._then(this._init,this._reject,void 0,this,r):(o._unsetRejectionIsUnhandled(),void this._reject(o._settledValue));if(o=o._settledValue,!u(o)){var s=new t.TypeError("expecting an array, a promise or a thenable");return void this.__hardReject__(s)}this._values=o}if(0===o.length)return void this._resolve(i(r));var l,f=o.length,h=f;l=this instanceof n.PropertiesPromiseArray?this._values:new Array(f);for(var p=!1,d=0;f>d;++d){var _=o[d];if(void 0!==_||c.call(o,d)){var v=t._cast(_,void 0);v instanceof t?v.isPending()?v._proxyPromiseArray(this,d):(v._unsetRejectionIsUnhandled(),p=!0):p=!0,l[d]=v}else h--}if(0===h)return void this._resolve(-2===r?l:i(r));if(this._values=l,this._length=h,p){var y=h===f?this._scanDirectValues:this._scanDirectValuesHoled;a.invoke(y,this,f)}},n.prototype._settlePromiseAt=function(e){var r=this._values[e];r instanceof t?r.isFulfilled()?this._promiseFulfilled(r._settledValue,e):r.isRejected()&&this._promiseRejected(r._settledValue,e):this._promiseFulfilled(r,e)},n.prototype._scanDirectValuesHoled=function(t){for(var e=0;t>e&&!this._isResolved();++e)c.call(this._values,e)&&this._settlePromiseAt(e)},n.prototype._scanDirectValues=function(t){for(var e=0;t>e&&!this._isResolved();++e)this._settlePromiseAt(e)},n.prototype._isResolved=function(){return null===this._values},n.prototype._resolve=function(t){this._values=null,this._promise._fulfill(t)},n.prototype.__hardReject__=n.prototype._reject=function(t){this._values=null;var e=o(t)?t:new Error(t+"");this._promise._attachExtraTrace(e),this._promise._reject(t,e)},n.prototype._promiseProgressed=function(t,e){this._isResolved()||this._promise._progress({index:e,value:t})},n.prototype._promiseFulfilled=function(t,e){if(!this._isResolved()){this._values[e]=t;var r=++this._totalResolved;r>=this._length&&this._resolve(this._values)}},n.prototype._promiseRejected=function(t){this._isResolved()||(this._totalResolved++,this._reject(t))},n}},function(t,e,r){"use strict";t.exports=function(){function t(t){var r;if("function"==typeof t)r="[function "+(t.name||"anonymous")+"]";else{r=t.toString();var i=/\[object [a-zA-Z0-9$_]+\]/;if(i.test(r))try{var n=JSON.stringify(t);r=n}catch(o){}0===r.length&&(r="(empty array)")}return"(<"+e(r)+">, no stack trace)"}function e(t){var e=41;return t.length<e?t:t.substr(0,e-3)+"..." | ||
}function i(t,e){this.captureStackTrace(i,e)}var n=r(12).inherits,o=r(39).defineProperty,s=new RegExp("\\b(?:[a-zA-Z0-9.]+\\$_\\w+|tryCatch(?:1|2|Apply)|new \\w*PromiseArray|\\w*PromiseArray\\.\\w*PromiseArray|setTimeout|CatchFilter\\$_\\w+|makeNodePromisified|processImmediate|process._tickCallback|nextTick|Async\\$\\w+)\\b"),a=null,c=null;n(i,Error),i.prototype.captureStackTrace=function(t,e){u(this,t,e)},i.possiblyUnhandledRejection=function(t){if("object"==typeof console){var e;if("object"==typeof t||"function"==typeof t){var r=t.stack;e="Possibly unhandled "+c(r,t)}else e="Possibly unhandled "+String(t);"function"==typeof console.error||"object"==typeof console.error?console.error(e):("function"==typeof console.log||"object"==typeof console.log)&&console.log(e)}},i.combine=function(t,e){for(var r=t.length-1,i=e.length-1;i>=0;--i){var n=e[i];if(t[r]!==n)break;t.pop(),r--}t.push("From previous event:");for(var o=t.concat(e),c=[],i=0,u=o.length;u>i;++i)s.test(o[i])||i>0&&!a.test(o[i])&&"From previous event:"!==o[i]||c.push(o[i]);return c},i.isSupported=function(){return"function"==typeof u};var u=function l(){if("number"==typeof Error.stackTraceLimit&&"function"==typeof Error.captureStackTrace){a=/^\s*at\s*/,c=function(e,r){return"string"==typeof e?e:void 0!==r.name&&void 0!==r.message?r.name+". "+r.message:t(r)};var e=Error.captureStackTrace;return function(t,r){e(t,r)}}var r=new Error;if("string"==typeof r.stack&&"function"==typeof"".startsWith&&r.stack.startsWith("stackDetection@")&&"stackDetection"===l.name){o(Error,"stackTraceLimit",{writable:!0,enumerable:!1,configurable:!1,value:25}),a=/@/;var i=/[@\n]/;return c=function(e,r){return"string"==typeof e?r.name+". "+r.message+"\n"+e:void 0!==r.name&&void 0!==r.message?r.name+". "+r.message:t(r)},function(t){for(var e=(new Error).stack,r=e.split(i),n=r.length,o="",s=0;n>s;s+=2)o+=r[s],o+="@",o+=r[s+1],o+="\n";t.stack=o}}return c=function(e,r){return"string"==typeof e?e:"object"!=typeof r&&"function"!=typeof r||void 0===r.name||void 0===r.message?t(r):r.name+". "+r.message},null}();return i}},function(t,e,r){"use strict";t.exports=function(t){function e(t,e,r){this._instances=t,this._callback=e,this._promise=r}function i(t,e){var r={},i=s(t,r,e);if(i===a)return i;var n=c(r);return n.length?(a.e=new u("Catch filter must inherit from Error or be a simple predicate function"),a):i}var n=r(12),o=r(14),s=n.tryCatch1,a=n.errorObj,c=r(39).keys,u=o.TypeError;return e.prototype.doFilter=function(e){for(var r=this._callback,n=this._promise,c=n._isBound()?n._boundTo:void 0,u=0,l=this._instances.length;l>u;++u){var f=this._instances[u],h=f===Error||null!=f&&f.prototype instanceof Error;if(h&&e instanceof f){var p=s(r,c,e);return p===a?(t.e=p.e,t):p}if("function"==typeof f&&!h){var d=i(f,e);if(d===a){var _=o.canAttach(a.e)?a.e:new Error(a.e+"");this._promise._attachExtraTrace(_),e=a.e;break}if(d){var p=s(r,c,e);return p===a?(t.e=p.e,t):p}}}return t.e=e,t},e}},function(t,e,r){"use strict";function i(t){return t instanceof Error&&d.getPrototypeOf(t)===Error.prototype}function n(t){var e;return e=i(t)?new f(t):t,u.markAsOriginatingFromRejection(e),e}function o(t){function e(e,r){if(null!==t){if(e){var i=n(c(e));t._attachExtraTrace(i),t._reject(i)}else if(arguments.length>2){for(var o=arguments.length,s=new Array(o-1),a=1;o>a;++a)s[a-1]=arguments[a];t._fulfill(s)}else t._fulfill(r);t=null}}return e}var s,a=r(12),c=a.maybeWrapAsError,u=r(14),l=u.TimeoutError,f=u.RejectionError,h=r(13),p=a.haveGetters,d=r(39);if(s=p?function(t){this.promise=t}:function(t){this.promise=t,this.asCallback=o(t),this.callback=this.asCallback},p){var _={get:function(){return o(this.promise)}};d.defineProperty(s.prototype,"asCallback",_),d.defineProperty(s.prototype,"callback",_)}s._nodebackForPromise=o,s.prototype.toString=function(){return"[object PromiseResolver]"},s.prototype.resolve=s.prototype.fulfill=function(t){var e=this.promise;if(void 0===e||void 0===e._tryFollow)throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.");e._tryFollow(t)||h.invoke(e._fulfill,e,t)},s.prototype.reject=function(t){var e=this.promise;if(void 0===e||void 0===e._attachExtraTrace)throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.");u.markAsOriginatingFromRejection(t);var r=u.canAttach(t)?t:new Error(t+"");e._attachExtraTrace(r),h.invoke(e._reject,e,t),r!==t&&h.invoke(this._setCarriedStackTrace,this,r)},s.prototype.progress=function(t){h.invoke(this.promise._progress,this.promise,t)},s.prototype.cancel=function(){h.invoke(this.promise.cancel,this.promise,void 0)},s.prototype.timeout=function(){this.reject(new l("timeout"))},s.prototype.isResolved=function(){return this.promise.isResolved()},s.prototype.toJSON=function(){return this.promise.toJSON()},s.prototype._setCarriedStackTrace=function(t){this.promise.isRejected()&&this.promise._setCarriedStackTrace(t)},t.exports=s},function(t,e,r){"use strict";t.exports=function(t){function e(e){var r=new i(e),n=t.rejected(r),o=n._peekContext();return null!=o&&o._attachExtraTrace(r),n}var i=r(14).TypeError;return e}},function(t,e,r){"use strict";t.exports=function(t,e){function i(){return this}function n(){throw this}function o(t){return function(){return t}}function s(t){return function(){throw t}}function a(t,e,r){var a;return a=f&&h(e)?r?o(e):s(e):r?i:n,t._then(a,p,void 0,e,void 0)}function c(r){var i=this.promise,n=this.handler,o=i._isBound()?n.call(i._boundTo):n();if(void 0!==o){var s=t._cast(o,void 0);if(s instanceof t)return a(s,r,i.isFulfilled())}return i.isRejected()?(e.e=r,e):r}function u(e){var r=this.promise,i=this.handler,n=r._isBound()?i.call(r._boundTo,e):i(e);if(void 0!==n){var o=t._cast(n,void 0);if(o instanceof t)return a(o,e,!0)}return e}var l=r(12),f=l.wrapsPrimitiveReceiver,h=l.isPrimitive,p=l.thrower;t.prototype._passThroughHandler=function(t,e){if("function"!=typeof t)return this.then();var r={promise:this,handler:t};return this._then(e?c:u,e?c:void 0,void 0,r,void 0)},t.prototype.lastly=t.prototype["finally"]=function(t){return this._passThroughHandler(t,!0)},t.prototype.tap=function(t){return this._passThroughHandler(t,!1)}}},function(t,e,r){"use strict";var i=r(12),n=i.isPrimitive,o=i.wrapsPrimitiveReceiver;t.exports=function(t){var e=function(){return this},r=function(){throw this},i=function(t,e){return 1===e?function(){throw t}:2===e?function(){return t}:void 0};t.prototype["return"]=t.prototype.thenReturn=function(t){return o&&n(t)?this._then(i(t,2),void 0,void 0,void 0,void 0):this._then(e,void 0,void 0,t,void 0)},t.prototype["throw"]=t.prototype.thenThrow=function(t){return o&&n(t)?this._then(i(t,1),void 0,void 0,void 0,void 0):this._then(r,void 0,void 0,t,void 0)}}},function(t,e,r){"use strict";t.exports=function(t,e){function i(t){try{return t.then}catch(e){return u.e=e,u}}function n(r,n){if(l(r)){if(r instanceof t)return r;if(o(r)){var a=new t(e);return a._setTrace(void 0),r._then(a._fulfillUnchecked,a._rejectUncheckedCheckError,a._progressUnchecked,a,null),a._setFollowing(),a}var f=i(r);if(f===u)return void 0!==n&&c(f.e)&&n._attachExtraTrace(f.e),t.reject(f.e);if("function"==typeof f)return s(r,f,n)}return r}function o(t){return f.call(t,"_promise0")}function s(e,r,i){function n(r){if(!u){if(u=!0,e===r){var n=t._makeSelfResolutionError();return void 0!==i&&i._attachExtraTrace(n),void a.promise._reject(n,void 0)}a.resolve(r)}}function o(t){if(!u){u=!0;var e=c(t)?t:new Error(t+"");void 0!==i&&i._attachExtraTrace(e),a.promise._reject(t,e)}}function s(t){if(!u){var e=a.promise;"function"==typeof e._progress&&e._progress(t)}}var a=t.defer(),u=!1;try{r.call(e,n,o,s)}catch(l){if(!u){u=!0;var f=c(l)?l:new Error(l+"");void 0!==i&&i._attachExtraTrace(f),a.promise._reject(l,f)}}return a.promise}var a=r(12),c=r(14).canAttach,u=a.errorObj,l=a.isObject,f={}.hasOwnProperty;t._cast=n}},function(t){"use strict";t.exports=function(t){function e(t){void 0!==t?(this._bitField=t._bitField,this._settledValue=t.isResolved()?t._settledValue:void 0):(this._bitField=0,this._settledValue=void 0)}e.prototype.isFulfilled=t.prototype.isFulfilled=function(){return(268435456&this._bitField)>0},e.prototype.isRejected=t.prototype.isRejected=function(){return(134217728&this._bitField)>0},e.prototype.isPending=t.prototype.isPending=function(){return 0===(402653184&this._bitField)},e.prototype.value=t.prototype.value=function(){if(!this.isFulfilled())throw new TypeError("cannot get fulfillment value of a non-fulfilled promise");return this._settledValue},e.prototype.error=t.prototype.reason=function(){if(!this.isRejected())throw new TypeError("cannot get rejection reason of a non-rejected promise");return this._settledValue},e.prototype.isResolved=t.prototype.isResolved=function(){return(402653184&this._bitField)>0},t.prototype.inspect=function(){return new e(this)},t.PromiseInspection=e}},function(t,e,r){"use strict";var i=r(11),n=function(t,e){for(var r=arguments.length,n=new Array(r-2),o=2;r>o;++o)n[o-2]=arguments[o];i.setTimeout(function(){t.apply(void 0,n)},e)};t.exports=function(t,e){var i=(r(12),r(14)),o=(r(19)(t),t.TimeoutError),s=function(t,e,r){if(t.isPending()){"string"!=typeof e&&(e="operation timed out after "+r+" ms");var n=new o(e);i.markAsOriginatingFromRejection(n),t._attachExtraTrace(n),t._rejectUnchecked(n)}},a=function(t,e){e._fulfill(t)},c=t.delay=function(r,i){void 0===i&&(i=r,r=void 0),i=+i;var o=t._cast(r,void 0),s=new t(e);return o instanceof t?(o._isBound()&&s._setBoundTo(o._boundTo),o._cancellable()&&(s._setCancellable(),s._cancellationParent=o),s._setTrace(o),s._follow(o),s.then(function(e){return t.delay(e,i)})):(s._setTrace(void 0),n(a,i,r,s),s)};t.prototype.delay=function(t){return c(this,t)},t.prototype.timeout=function(r,i){r=+r;var o=new t(e);return o._setTrace(this),this._isBound()&&o._setBoundTo(this._boundTo),this._cancellable()&&(o._setCancellable(),o._cancellationParent=this),o._follow(this),n(s,r,o,i,r),o}}},function(t,e,r){"use strict";t.exports=function(t,e,i){function n(t,r){var i=e(t,o,r===!0&&t._isBound()?t._boundTo:void 0),n=i.promise();return n.isRejected()?n:(i.setHowMany(1),i.setUnwrap(),i.init(),n)}var o=r(42)(i);t.any=function(t){return n(t,!1)},t.prototype.any=function(){return n(this,!0)}}},function(t,e,r){"use strict";t.exports=function(t,e){function i(r,i){var c=t._cast(r,void 0);if(c instanceof t)return s(c);if(!o(r))return n("expecting an array, a promise or a thenable");var u=new t(e);u._setTrace(i),void 0!==i&&(i._isBound()&&u._setBoundTo(i._boundTo),i._cancellable()&&(u._setCancellable(),u._cancellationParent=i));for(var l=u._fulfill,f=u._reject,h=0,p=r.length;p>h;++h){var d=r[h];(void 0!==d||a.call(r,h))&&t.cast(d)._then(l,f,void 0,u,null)}return u}var n=r(19)(t),o=r(12).isArray,s=function(t){return t.then(function(e){return i(e,t)})},a={}.hasOwnProperty;t.race=function(t){return i(t,void 0)},t.prototype.race=function(){return i(this,void 0)}}},function(t){"use strict";t.exports=function(t){function e(t){var e="string"==typeof this?this:""+this;return t[e]}t.prototype.call=function(t){for(var e=arguments.length,r=new Array(e-1),i=1;e>i;++i)r[i-1]=arguments[i];return this._then(function(e){return e[t].apply(e,r)},void 0,void 0,void 0,void 0)},t.prototype.get=function(t){return this._then(e,void 0,void 0,t,void 0)}}},function(t,e,r){"use strict";t.exports=function(t){function e(e){for(var r=this instanceof t?this._settledValue:this,i=r.length,n=new Array(i),o=0,s=0;i>s;++s)e[s]&&(n[o++]=r[s]);return n.length=o,n}var i=(r(12).isArray,{ref:null});t.filter=function(r,n){return t.map(r,n,i)._then(e,void 0,void 0,i.ref,void 0)},t.prototype.filter=function(t){return this.map(t,i)._then(e,void 0,void 0,i.ref,void 0)}}},function(t,e,r){"use strict";t.exports=function(t,e,i){var n=r(43)(t,i),o=r(14),s=o.TypeError,a=r(12).deprecated;t.coroutine=function(t){if("function"!=typeof t)throw new s("generatorFunction must be a function");var e=n;return function(){var r=t.apply(this,arguments),i=new e(void 0,void 0);return i._generator=r,i._next(void 0),i.promise()}},t.coroutine.addYieldHandler=n.addYieldHandler,t.spawn=function(r){if(a("Promise.spawn is deprecated. Use Promise.coroutine instead."),"function"!=typeof r)return e("generatorFunction must be a function");var i=new n(r,this),o=i.promise();return i._run(t.spawn),o}}},function(t,e,r){"use strict";t.exports=function(t,e,i,n){function o(t){return s(t,this[0],this[1],this[2])}function s(e,r,s,c){if("function"!=typeof r)return n("fn must be a function");var u=void 0;s===!0?e._isBound()&&(u=e._boundTo):s!==!1&&(u=s);var l=void 0!==c;if(l&&(c.ref=e),e instanceof t){var h=[r,u,c];return e._then(o,void 0,void 0,h,void 0)}if(!f(e))return n("expecting an array, a promise or a thenable");var p=new t(i);void 0!==u&&p._setBoundTo(u),p._setTrace(void 0);var d=new a(p,r,e,u,l);return d.init(),p}function a(t,e,r,i,n){this.shouldUnwrapItems=n,this.index=0,this.items=r,this.callback=e,this.receiver=i,this.promise=t,this.result=new Array(r.length)}var c=t.all,u=r(12),l=r(14).canAttach,f=u.isArray,h=t._cast,p={};u.inherits(a,e),a.prototype.init=function(){for(var e=this.items,r=e.length,i=this.result,n=!1,o=0;r>o;++o){var s=h(e[o],void 0);s instanceof t?s.isPending()?(i[o]=p,s._proxyPromiseArray(this,o)):s.isFulfilled()?i[o]=s.value():(s._unsetRejectionIsUnhandled(),n||(this.reject(s.reason()),n=!0)):i[o]=s}n||this.iterate()},a.prototype.isResolved=function(){return null===this.promise},a.prototype._promiseProgressed=function(t){this.isResolved()||this.promise._progress(t)},a.prototype._promiseFulfilled=function(t,e){this.isResolved()||(this.result[e]=t,this.shouldUnwrapItems&&(this.items[e]=t),this.index===e&&this.iterate())},a.prototype._promiseRejected=function(t){this.reject(t)},a.prototype.reject=function(t){if(!this.isResolved()){var e=l(t)?t:new Error(t+"");this.promise._attachExtraTrace(e),this.promise._reject(t,e)}},a.prototype.iterate=function(){for(var t=this.index,e=this.items,r=this.result,i=e.length,r=this.result,n=this.receiver,o=this.callback;i>t;++t){var s=r[t];if(s===p)return void(this.index=t);try{r[t]=o.call(n,s,t,i)}catch(a){return this.reject(a)}}this.promise._follow(c(r)),this.items=this.result=this.callback=this.promise=null},t.prototype.map=function(t,e){return s(this,t,!0,e)},t.map=function(t,e,r){return s(t,e,!1,r)}}},function(t,e,r){"use strict";t.exports=function(t){function e(t){throw t}function i(t,r){var i=this,n=void 0===t?c(i,r,null):a(i,r,null,t);n===u&&s.invokeLater(e,void 0,n.e)}function n(t,r){var i=this,n=c(i,r,t);n===u&&s.invokeLater(e,void 0,n.e)}var o=r(12),s=r(13),a=o.tryCatch2,c=o.tryCatch1,u=o.errorObj;t.prototype.nodeify=function(t){return"function"==typeof t&&this._then(i,n,void 0,t,this._isBound()?this._boundTo:null),this}}},function(t,e,r){"use strict";t.exports=function(t,e){function i(t){return t.__isPromisified__===!0}function n(t,e){var r=e+"Async"in t;return r?i(t[e+"Async"]):!1}function o(t){for(var e=0;e<t.length;e+=2){var r=t[e];if(k.test(r))for(var i=r.replace(k,""),n=0;n<t.length;n+=2)if(t[n]===i)throw new b("Cannot promisify an API that has normal methods with Async-suffix")}}function s(t){for(var e=[t],r=Math.max(0,t-1-5),i=t-1;i>=r;--i)i!==t&&e.push(i);for(var i=t+1;5>=i;++i)e.push(i);return e}function a(t){for(var e=new Array(t),r=0;r<e.length;++r)e[r]="_arg"+r;return e.join(", ")}function c(t){return"number"==typeof t.length?Math.max(Math.min(t.length,1024),0):0}function u(t){return x.test(t)?"."+t:"['"+t.replace(/(['\\])/g,"\\$1")+"']"}function l(r,i,n,o){function l(t){for(var e=new Array(t),n=0,o=e.length;o>n;++n)e[n]="arguments["+n+"]";var s=t>0?",":"";return"string"==typeof r&&i===p?"this"+u(r)+"("+e.join(",")+s+" fn);break;":(void 0===i?"callback("+e.join(",")+s+" fn);":"callback.call("+(i===p?"this":"receiver")+", "+e.join(",")+s+" fn);")+"break;"}function f(){for(var t="",e=0;e<d.length;++e)t+="case "+d[e]+":"+l(d[e]);return t+="default: var args = new Array(len + 1);var i = 0;for (var i = 0; i < len; ++i) { args[i] = arguments[i];}args[i] = fn;"+("string"==typeof r?"this"+u(r)+".apply(":"callback.apply(")+(i===p?"this":"receiver")+", args); break;"}var h=Math.max(0,c(o)-1),d=s(h),_="string"==typeof n?n+"Async":"promisified";return x.test(_)||(_="promisified"),new Function("Promise","callback","receiver","withAppended","maybeWrapAsError","nodebackForPromise","INTERNAL","var ret = function "+_+"("+a(h)+') {"use strict";var len = arguments.length;var promise = new Promise(INTERNAL);promise._setTrace(void 0);var fn = nodebackForPromise(promise);try {switch(len) {'+f()+"}}catch(e){ var wrapped = maybeWrapAsError(e);promise._attachExtraTrace(wrapped);promise._reject(wrapped);}return promise;}; ret.__isPromisified__ = true; return ret;")(t,r,i,y,m,v,e)}function f(r,i){function n(){var n=i;i===p&&(n=this),"string"==typeof r&&(r=n[r]);var o=new t(e);o._setTrace(void 0);var s=v(o);try{r.apply(n,y(arguments,s))}catch(a){var c=m(a);o._attachExtraTrace(c),o._reject(c)}return o}return n.__isPromisified__=!0,n}function h(t,e,r){if(r){for(var i=j(t),n=0,o=i.length;o>n;n+=2){var s=i[n],a=i[n+1],c=s+"Async";t[c]=T(s,p,s,a)}return d.toFastProperties(t),t}return T(t,e,void 0,t)}var p={},d=r(12),_=r(39),v=r(18)._nodebackForPromise,y=d.withAppended,m=d.maybeWrapAsError,w=d.canEvaluate,g=d.deprecated,b=r(14).TypeError,k=new RegExp("Async$"),j=function(){if(_.isES5){var t=Object.create,e=Object.getOwnPropertyDescriptor;return function(r){for(var s=[],a=t(null),c=r;null!==r;){for(var u=_.keys(r),l=0,f=u.length;f>l;++l){var h=u[l];if(!a[h]){a[h]=!0;var p=e(r,h);null==p||"function"!=typeof p.value||i(p.value)||n(c,h)||s.push(h,p.value)}}r=_.getPrototypeOf(r)}return o(s),s}}return function(t){var e=[];for(var r in t){var s=t[r];"function"!=typeof s||i(s)||n(t,r)||e.push(r,s)}return o(e),e}}(),x=/^[a-z$_][a-z$_0-9]*$/i,T=w?l:f;t.promisify=function(t,e){if("object"==typeof t&&null!==t)return g("Promise.promisify for promisifying entire objects is deprecated. Use Promise.promisifyAll instead."),h(t,e,!0);if("function"!=typeof t)throw new b("fn must be a function");return i(t)?t:h(t,arguments.length<2?p:e,!1)},t.promisifyAll=function(t){if("function"!=typeof t&&"object"!=typeof t)throw new b("the target of promisifyAll must be an object or a function");return h(t,void 0,!0)}}},function(t,e,r){"use strict";t.exports=function(t,e){function i(e,r){var i,o=t._cast(e,void 0);return a(o)?(o instanceof t?i=o._then(t.props,void 0,void 0,void 0,void 0):(i=new n(o,r===!0&&o._isBound()?o._boundTo:void 0).promise(),r=!1),r===!0&&o._isBound()&&i._setBoundTo(o._boundTo),i):s("cannot await properties of a non-object")}var n=r(44)(t,e),o=r(12),s=r(19)(t),a=o.isObject;t.prototype.props=function(){return i(this,!0)},t.props=function(t){return i(t,!1)}}},function(t){"use strict";t.exports=function(t,e,r,i,n){function o(e,r,i,o,s){this.promise=new t(n),this.index=r,this.length=o.length,this.items=o,this.callback=e,this.receiver=s,this.accum=i}function s(t,e){var r=this,i=void 0;"function"!=typeof r&&(i=r.receiver,r=r.fn);var n=t.length,s=void 0,a=0;void 0!==e?(s=e,a=0):(a=1,n>0&&(s=t[0]));var c=a;if(c>=n)return s;var u=new o(r,c,s,t,i);return u.iterate(),u.promise}function a(t){var e=this.fn,r=this.initialValue;return s.call(e,t,r)}function c(t,e,r,i){return r._then(function(r){return u(t,e,r,i)},void 0,void 0,void 0,void 0)}function u(n,o,u,l){if("function"!=typeof o)return i("fn must be a function");if(l===!0&&n._isBound()&&(o={fn:o,receiver:n._boundTo}),void 0!==u){if(u instanceof t){if(!u.isFulfilled())return c(n,o,u,l);u=u._settledValue}return e(n,r,l===!0&&n._isBound()?n._boundTo:void 0).promise()._then(a,void 0,void 0,{fn:o,initialValue:u},void 0)}return e(n,r,l===!0&&n._isBound()?n._boundTo:void 0).promise()._then(s,void 0,void 0,o,void 0)}o.prototype.reject=function(t){this.promise._reject(t)},o.prototype.fulfill=function(t,e){this.accum=t,this.index=e+1,this.iterate()},o.prototype.iterate=function(){for(var e=this.index,r=this.length,i=this.items,n=this.accum,o=this.receiver,s=this.callback;r>e;++e)if(n=s.call(o,n,i[e],e,r),n=t._cast(n,void 0),n instanceof t)return void n._then(this.fulfill,this.reject,void 0,this,e);this.promise._fulfill(n)},t.reduce=function(t,e,r){return u(t,e,r,!1)},t.prototype.reduce=function(t,e){return u(this,t,e,!0)}}},function(t,e,r){"use strict";t.exports=function(t,e,i){function n(t,r){return e(t,o,r===!0&&t._isBound()?t._boundTo:void 0).promise()}var o=r(45)(t,i);t.settle=function(t){return n(t,!1)},t.prototype.settle=function(){return n(this,!0)}}},function(t,e,r){"use strict";t.exports=function(t,e,i,n){function o(t,r,i){if((0|r)!==r||0>r)return n("expecting a positive integer");var o=e(t,s,i===!0&&t._isBound()?t._boundTo:void 0),a=o.promise();return a.isRejected()?a:(o.setHowMany(r),o.init(),a)}var s=r(42)(i);t.some=function(t,e){return o(t,e,!1)},t.prototype.some=function(t){return o(this,t,!0)}}},function(t,e,r){"use strict";t.exports=function(t,e){var i=r(12),n=r(13),o=r(14),s=i.tryCatch1,a=i.errorObj;t.prototype.progressed=function(t){return this._then(void 0,void 0,t,void 0,void 0)},t.prototype._progress=function(t){this._isFollowingOrFulfilledOrRejected()||this._progressUnchecked(t)},t.prototype._progressHandlerAt=function(t){return 0===t?this._progressHandler0:this[t+2-5]},t.prototype._doProgressWith=function(e){var r=e.value,i=e.handler,n=e.promise,c=e.receiver;this._pushContext();var u=s(i,c,r);if(this._popContext(),u===a){if(null!=u.e&&"StopProgressPropagation"!==u.e.name){var l=o.canAttach(u.e)?u.e:new Error(u.e+"");n._attachExtraTrace(l),n._progress(u.e)}}else u instanceof t?u._then(n._progress,null,null,n,void 0):n._progress(u)},t.prototype._progressUnchecked=function(r){if(this.isPending())for(var i=this._length(),o=this._progress,s=0;i>s;s+=5){var a=this._progressHandlerAt(s),c=this._promiseAt(s);if(c instanceof t)"function"==typeof a?n.invoke(this._doProgressWith,this,{handler:a,promise:c,receiver:this._receiverAt(s),value:r}):n.invoke(o,c,r);else{var u=this._receiverAt(s);"function"==typeof a?a.call(u,r,c):u instanceof t&&u._isProxied()?u._progressUnchecked(r):e(u,c)&&u._promiseProgressed(r,c)}}}}},function(t,e,r){"use strict";t.exports=function(t,e){var i=r(14),n=r(13),o=i.CancellationError;t.prototype._cancel=function(){if(!this.isCancellable())return this;for(var t,e=this;void 0!==(t=e._cancellationParent)&&t.isCancellable();)e=t;var r=new o;e._attachExtraTrace(r),e._rejectUnchecked(r)},t.prototype.cancel=function(){return this.isCancellable()?(n.invokeLater(this._cancel,this,void 0),this):this},t.prototype.cancellable=function(){return this._cancellable()?this:(this._setCancellable(),this._cancellationParent=void 0,this)},t.prototype.uncancellable=function(){var r=new t(e);return r._setTrace(this),r._follow(this),r._unsetCancellable(),this._isBound()&&r._setBoundTo(this._boundTo),r},t.prototype.fork=function(t,e,r){var i=this._then(t,e,r,void 0,void 0);return i._setCancellable(),i._cancellationParent=void 0,i}}},function(t){var e=function(){"use strict";return void 0===this}();if(e)t.exports={freeze:Object.freeze,defineProperty:Object.defineProperty,keys:Object.keys,getPrototypeOf:Object.getPrototypeOf,isArray:Array.isArray,isES5:e};else{var r={}.hasOwnProperty,i={}.toString,n={}.constructor.prototype,o=function(t){var e=[];for(var i in t)r.call(t,i)&&e.push(i);return e},s=function(t,e,r){return t[e]=r.value,t},a=function(t){return t},c=function(t){try{return Object(t).constructor.prototype}catch(e){return n}},u=function(t){try{return"[object Array]"===i.call(t)}catch(e){return!1}};t.exports={isArray:u,keys:o,defineProperty:s,freeze:a,getPrototypeOf:c,isES5:e}}},function(t,e,r){(function(e){"use strict";var i,n=r(11);if("undefined"!=typeof e&&null!==e&&"function"==typeof e.cwd&&"function"==typeof e.nextTick&&"string"==typeof e.version)i=function(t){e.nextTick(t)};else if("function"!=typeof n.MutationObserver&&"function"!=typeof n.WebkitMutationObserver&&"function"!=typeof n.WebKitMutationObserver||"undefined"==typeof document||"function"!=typeof document.createElement)if("function"==typeof n.postMessage&&"function"!=typeof n.importScripts&&"function"==typeof n.addEventListener&&"function"==typeof n.removeEventListener){var o="bluebird_message_key_"+Math.random();i=function(){function t(t){if(t.source===n&&t.data===o){var r=e;e=void 0,r()}}var e=void 0;return n.addEventListener("message",t,!1),function(t){e=t,n.postMessage(o,"*")}}()}else i="function"==typeof n.MessageChannel?function(){var t=void 0,e=new n.MessageChannel;return e.port1.onmessage=function(){var e=t;t=void 0,e()},function(r){t=r,e.port2.postMessage(null)}}():n.setTimeout?function(t){setTimeout(t,4)}:function(t){t()};else i=function(){var t=n.MutationObserver||n.WebkitMutationObserver||n.WebKitMutationObserver,e=document.createElement("div"),r=void 0,i=new t(function(){var t=r;r=void 0,t()});return i.observe(e,{attributes:!0}),function(t){r=t,e.setAttribute("class","foo")}}();t.exports=i}).call(e,r(7))},function(t){"use strict";function e(t,e,r,i,n){for(var o=0;n>o;++o)r[o+i]=t[o+e]}function r(t){return t>>>=0,t-=1,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,t+1}function i(t){return"number"!=typeof t?16:r(Math.min(Math.max(16,t),1073741824))}function n(t){this._capacity=i(t),this._length=0,this._front=0,this._makeCapacity()}n.prototype._willBeOverCapacity=function(t){return this._capacity<t},n.prototype._pushOne=function(t){var e=this.length();this._checkCapacity(e+1);var r=this._front+e&this._capacity-1;this[r]=t,this._length=e+1},n.prototype.push=function(t,e,r){var i=this.length()+3;if(this._willBeOverCapacity(i))return this._pushOne(t),this._pushOne(e),void this._pushOne(r);var n=this._front+i-3;this._checkCapacity(i);var o=this._capacity-1;this[n+0&o]=t,this[n+1&o]=e,this[n+2&o]=r,this._length=i},n.prototype.shift=function(){var t=this._front,e=this[t];return this[t]=void 0,this._front=t+1&this._capacity-1,this._length--,e},n.prototype.length=function(){return this._length},n.prototype._makeCapacity=function(){for(var t=this._capacity,e=0;t>e;++e)this[e]=void 0},n.prototype._checkCapacity=function(t){this._capacity<t&&this._resizeTo(this._capacity<<3)},n.prototype._resizeTo=function(t){var r=this._front,i=this._capacity,n=new Array(i),o=this.length();if(e(this,0,n,0,i),this._capacity=t,this._makeCapacity(),this._front=0,i>=r+o)e(n,r,this,0,o);else{var s=o-(r+o&i-1);e(n,r,this,0,s),e(n,0,this,s,o-s)}},t.exports=n},function(t,e,r){"use strict";t.exports=function(t){function e(t,e){this.constructor$(t,e),this._howMany=0,this._unwrap=!1,this._initialized=!1}var i=r(12),n=r(14).RangeError,o=i.inherits,s=i.isArray;return o(e,t),e.prototype._init=function(){if(this._initialized){if(0===this._howMany)return void this._resolve([]);this._init$(void 0,-2);var t=s(this._values);if(this._holes=t?this._values.length-this.length():0,!this._isResolved()&&t&&this._howMany>this._canPossiblyFulfill()){var e="(Promise.some) input array contains less than "+this._howMany+" promises";this._reject(new n(e))}}},e.prototype.init=function(){this._initialized=!0,this._init()},e.prototype.setUnwrap=function(){this._unwrap=!0},e.prototype.howMany=function(){return this._howMany},e.prototype.setHowMany=function(t){this._isResolved()||(this._howMany=t)},e.prototype._promiseFulfilled=function(t){this._isResolved()||(this._addFulfilled(t),this._fulfilled()===this.howMany()&&(this._values.length=this.howMany(),this._resolve(1===this.howMany()&&this._unwrap?this._values[0]:this._values)))},e.prototype._promiseRejected=function(t){this._isResolved()||(this._addRejected(t),this.howMany()>this._canPossiblyFulfill()&&this._reject(this._values.length===this.length()?[]:this._values.slice(this.length()+this._holes)))},e.prototype._fulfilled=function(){return this._totalResolved},e.prototype._rejected=function(){return this._values.length-this.length()-this._holes},e.prototype._addRejected=function(t){this._values.push(t)},e.prototype._addFulfilled=function(t){this._values[this._totalResolved++]=t},e.prototype._canPossiblyFulfill=function(){return this.length()-this._rejected()},e}},function(t,e,r){"use strict";t.exports=function(t,e){function i(e){for(var r=f,n=u,o=t,s=r.length,a=0;s>a;++a){var c=l(r[a],void 0,e);if(c===n)return o.reject(n.e);var h=o._cast(c,i,void 0);if(h instanceof o)return h}return null}function n(r,i){var n=this._promise=new t(e);n._setTrace(void 0),this._generatorFunction=r,this._receiver=i,this._generator=void 0}var o=r(14),s=o.TypeError,a=r(12),c=a.isArray,u=a.errorObj,l=a.tryCatch1,f=[];return n.prototype.promise=function(){return this._promise},n.prototype._run=function(){this._generator=this._generatorFunction.call(this._receiver),this._receiver=this._generatorFunction=void 0,this._next(void 0)},n.prototype._continue=function h(e){if(e===u){this._generator=void 0;var r=o.canAttach(e.e)?e.e:new Error(e.e+"");return this._promise._attachExtraTrace(r),void this._promise._reject(e.e,r)}var n=e.value;if(e.done===!0)this._generator=void 0,this._promise._tryFollow(n)||this._promise._fulfill(n);else{var a=t._cast(n,h,void 0);if(!(a instanceof t)&&(a=c(a)?t.all(a):i(a),null===a))return void this._throw(new s("A value was yielded that could not be treated as a promise"));a._then(this._next,this._throw,void 0,this,null)}},n.prototype._throw=function(t){o.canAttach(t)&&this._promise._attachExtraTrace(t),this._continue(l(this._generator["throw"],this._generator,t))},n.prototype._next=function(t){this._continue(l(this._generator.next,this._generator,t))},n.addYieldHandler=function(t){if("function"!=typeof t)throw new s("fn must be a function");f.push(t)},n}},function(t,e,r){"use strict";t.exports=function(t,e){function i(t,e){for(var r=s.keys(t),i=new Array(r.length),n=0,o=i.length;o>n;++n)i[n]=t[r[n]];if(this.constructor$(i,e),!this._isResolved())for(var n=0,o=r.length;o>n;++n)i.push(r[n])}var n=r(12),o=n.inherits,s=r(39);return o(i,e),i.prototype._init=function(){this._init$(void 0,-3)},i.prototype._promiseFulfilled=function(t,e){if(!this._isResolved()){this._values[e]=t;var r=++this._totalResolved;if(r>=this._length){for(var i={},n=this.length(),o=0,s=this.length();s>o;++o)i[this._values[o+n]]=this._values[o];this._resolve(i)}}},i.prototype._promiseProgressed=function(t,e){this._isResolved()||this._promise._progress({key:this._values[e+this.length()],value:t})},e.PropertiesPromiseArray=i,i}},function(t,e,r){"use strict";t.exports=function(t,e){function i(t,e){this.constructor$(t,e)}var n=t.PromiseInspection,o=r(12),s=o.inherits;return s(i,e),i.prototype._promiseResolved=function(t,e){this._values[t]=e;var r=++this._totalResolved;r>=this._length&&this._resolve(this._values)},i.prototype._promiseFulfilled=function(t,e){if(!this._isResolved()){var r=new n;r._bitField=268435456,r._settledValue=t,this._promiseResolved(e,r)}},i.prototype._promiseRejected=function(t,e){if(!this._isResolved()){var r=new n;r._bitField=134217728,r._settledValue=t,this._promiseResolved(e,r)}},i}}])}); | ||
!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("os"),require("child_process")):"function"==typeof define&&define.amd?define(["os","child_process"],e):"object"==typeof exports?exports.workerpool=e(require("os"),require("child_process")):r.workerpool=e(r.os,r.child_process)}(this,function(__WEBPACK_EXTERNAL_MODULE_6__,__WEBPACK_EXTERNAL_MODULE_8__){return function(r){function e(o){if(t[o])return t[o].exports;var n=t[o]={exports:{},id:o,loaded:!1};return r[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var t={};return e.m=r,e.c=t,e.p="",e(0)}([function(r,e,t){e.pool=function(r){var e=t(1);return new e(r)},e.worker=function o(r){var e=t(2);if("browser"==e){var n=new Blob([t(3)],{type:"text/javascript"}),i=window.URL.createObjectURL(n);importScripts(i)}else var o=t(4);o.add(r)},e.Promise=t(5)},function(r,e,t){function o(r,e){if("string"==typeof r?this.script=r||null:(this.script=null,e=r),e&&"maxWorkers"in e){if(!n(e.maxWorkers)||!i(e.maxWorkers)||e.maxWorkers<1)throw new TypeError("Option maxWorkers must be a positive integer number");this.maxWorkers=e.maxWorkers}else{var o=t(2),s="browser"==o?4:t(6).cpus().length;this.maxWorkers=Math.max(s-1,1)}this.workers=[],this.tasks=[]}function n(r){return"number"==typeof r}function i(r){return Math.round(r)==r}var s=t(5),c=t(7);o.prototype.run=function(r,e){if("function"!=typeof r)throw new TypeError('Function expected as argument "fn"');if(e&&!Array.isArray(e))throw new TypeError('Array expected as argument "args"');return this.exec("run",[String(r),e])},o.prototype.exec=function(r,e){var t=s.defer();return this.tasks.push({method:r,params:e,resolver:t}),this._next(),t.promise},o.prototype.proxy=function(){var r=this;return this.exec("methods").then(function(e){var t={};return e.forEach(function(e){t[e]=function(){return r.exec(e,Array.prototype.slice.call(arguments))}}),t})},o.prototype._next=function(){if(this.tasks.length>0){var r=this._getWorker();if(r){var e=this,t=this.tasks.shift();t.resolver.promise.pending&&r.exec(t.method,t.params,t.resolver).then(function(){e._next()}).catch(function(){r.terminated&&e._removeWorker(r),e._next()})}}},o.prototype._getWorker=function(){for(var r=0,e=this.workers.length;e>r;r++){var t=this.workers[r];if(!t.busy())return t}return this.workers.length<this.maxWorkers?(t=new c(this.script),this.workers.push(t),t):null},o.prototype._removeWorker=function(r){r.terminate();var e=this.workers.indexOf(r);-1!=e&&this.workers.splice(e,1)},o.prototype.clear=function(r){this.workers.forEach(function(e){e.terminate(r)}),this.workers=[]},r.exports=o},function(r){r.exports="undefined"!=typeof window?"browser":"node"},function(r){r.exports='function isPromise(e){return e&&"function"==typeof e.then&&"function"==typeof e.catch}var worker={};if("undefined"!=typeof self&&"function"==typeof postMessage&&"function"==typeof addEventListener)worker.on=function(e,r){addEventListener(e,function(e){r(e.data)})},worker.send=function(e){postMessage(e)};else{if("undefined"==typeof process)throw new Error("Script must be executed as a worker");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}worker.methods={},worker.methods.run=function run(fn,args){var f=eval("("+fn+")");return f.apply(f,args)},worker.methods.methods=function(){return Object.keys(worker.methods)},worker.on("message",function(e){try{var r=worker.methods[e.method];if(!r)throw new Error(\'Unknown method "\'+e.method+\'"\');var o=r.apply(r,e.params);isPromise(o)?o.then(function(r){worker.send({id:e.id,result:r,error:null})}).catch(function(r){worker.send({id:e.id,result:null,error:r.toString()})}):worker.send({id:e.id,result:o,error:null})}catch(n){worker.send({id:e.id,result:null,error:n.toString()})}}),worker.register=function(e){if(e)for(var r in e)e.hasOwnProperty(r)&&(worker.methods[r]=e[r])},"undefined"!=typeof exports&&(exports.add=worker.register);'},function(module,exports,__webpack_require__){function isPromise(r){return r&&"function"==typeof r.then&&"function"==typeof r.catch}var worker={};if("undefined"!=typeof self&&"function"==typeof postMessage&&"function"==typeof addEventListener)worker.on=function(r,e){addEventListener(r,function(r){e(r.data)})},worker.send=function(r){postMessage(r)};else{if("undefined"==typeof process)throw new Error("Script must be executed as a worker");worker.on=process.on.bind(process),worker.send=process.send.bind(process)}worker.methods={},worker.methods.run=function run(fn,args){var f=eval("("+fn+")");return f.apply(f,args)},worker.methods.methods=function(){return Object.keys(worker.methods)},worker.on("message",function(r){try{var e=worker.methods[r.method];if(!e)throw new Error('Unknown method "'+r.method+'"');var t=e.apply(e,r.params);isPromise(t)?t.then(function(e){worker.send({id:r.id,result:e,error:null})}).catch(function(e){worker.send({id:r.id,result:null,error:e.toString()})}):worker.send({id:r.id,result:t,error:null})}catch(o){worker.send({id:r.id,result:null,error:o.toString()})}}),worker.register=function(r){if(r)for(var e in r)r.hasOwnProperty(e)&&(worker.methods[e]=r[e])},exports.add=worker.register},function(r){"use strict";function e(r,i){var s=this;if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if("function"!=typeof r)throw new SyntaxError("Function parameter handler(resolve, reject) missing");var c=[],u=[];this.resolved=!1,this.rejected=!1,this.pending=!0;var a=function(r,e){c.push(r),u.push(e)};this.then=function(r,o){return new e(function(e,n){var i=r?t(r,e,n):e,s=o?t(o,e,n):n;a(i,s)},s)};var f=function(r){return s.resolved=!0,s.rejected=!1,s.pending=!1,c.forEach(function(e){e(r)}),a=function(e){e(r)},f=p=function(){throw new Error("Promise is already resolved")},s},p=function(r){return s.resolved=!1,s.rejected=!0,s.pending=!1,u.forEach(function(e){e(r)}),a=function(e,t){t(r)},f=p=function(){throw new Error("Promise is already resolved")},s};this.cancel=function(){return i?i.cancel():p(new o),s},this.timeout=function(r){if(i)i.timeout(r);else{var e=setTimeout(function(){p(new n("Promise timed out after "+r+" ms"))},r);s.always(function(){clearTimeout(e)})}return s},r(function(r){f(r)},function(r){p(r)})}function t(r,e,t){return function(o){try{var n=r(o);n&&"function"==typeof n.then&&"function"==typeof n["catch"]?n.then(e,t):e(n)}catch(i){t(i)}}}function o(r){this.message=r||"promise cancelled",this.stack=(new Error).stack}function n(r){this.message=r||"timeout exceeded",this.stack=(new Error).stack}e.prototype["catch"]=function(r){return this.then(null,r)},e.prototype.always=function(r){return this.then(r,r)},e.all=function(r){return new e(function(e,t){var o=r.length,n=[];o?r.forEach(function(r,i){r.then(function(r){n[i]=r,o--,0==o&&e(n)},function(r){o=0,t(r)})}):e(n)})},e.defer=function(){var r={};return r.promise=new e(function(e,t){r.resolve=e,r.reject=t}),r},o.prototype=new Error,o.prototype.constructor=Error,o.prototype.name="CancellationError",e.CancellationError=o,n.prototype=new Error,n.prototype.constructor=Error,n.prototype.name="TimeoutError",e.TimeoutError=n,r.exports=e},function(r){r.exports=require("os")},function(r,e,t){function o(){if("browser"==s){if("undefined"==typeof Blob)throw new Error("Blob not supported by the browser");if(!window.URL||"function"!=typeof window.URL.createObjectURL)throw new Error("URL.createObjectURL not supported by the browser");var r=new Blob([t(3)],{type:"text/javascript"});return window.URL.createObjectURL(r)}return __dirname+"/worker.js"}function n(r){function e(r){n.terminated=!0;for(var e in n.processing)n.processing.hasOwnProperty(e)&&n.processing[e].resolver.reject(r);n.processing={}}if(this.script=r||o(),"browser"==s){if("function"!=typeof Worker)throw new Error("Web workers not supported by the browser");this.worker=new Worker(this.script),this.worker.on=function(r,e){this.addEventListener(r,function(r){e(r.data)})},this.worker.send=function(r){this.postMessage(r)}}else this.worker=t(8).fork(this.script);var n=this;this.worker.on("message",function(r){var e=r.id,t=n.processing[e];t&&(delete n.processing[e],n.terminating&&n.terminate(),r.error?t.resolver.reject(r.error):t.resolver.resolve(r.result))}),this.worker.on("error",e),this.worker.on("exit",function(){var r=new Error("Worker terminated unexpectedly");e(r)}),this.processing={},this.terminating=!1,this.terminated=!1,this.lastId=0}var i=t(5),s=t(2);n.prototype.methods=function(){return this.exec("methods")},n.prototype.exec=function(r,e,t){t||(t=i.defer());var o=++this.lastId;this.processing[o]={id:o,resolver:t};var n={id:o,method:r,params:e};this.terminated?t.reject(new Error("Worker is terminated")):this.worker.send(n);var s=this;return t.promise.catch(function(r){(r instanceof i.CancellationError||r instanceof i.TimeoutError)&&(delete s.processing[o],s.terminate(!0))}),t.promise},n.prototype.busy=function(){return Object.keys(this.processing).length>0},n.prototype.terminate=function(r){if(r){for(var e in this.processing)this.processing.hasOwnProperty(e)&&this.processing[e].resolver.reject(new Error("Worker terminated"));this.processing={}}if(this.busy())this.terminating=!0;else{if(this.worker){if("function"==typeof this.worker.kill)this.worker.kill();else{if("function"!=typeof this.worker.terminate)throw new Error("Failed to terminate worker");this.worker.terminate()}this.worker=null}this.terminating=!1,this.terminated=!0}},r.exports=n},function(r){r.exports=require("child_process")}])}); | ||
//# sourceMappingURL=workerpool.map |
@@ -5,2 +5,8 @@ # workerpool history | ||
## 2014-05-14, version 0.2.0 | ||
- Implemented support for cancelling running tasks. | ||
- Implemented support for cancelling running tasks after a timeout. | ||
## 2014-05-07, version 0.1.0 | ||
@@ -7,0 +13,0 @@ |
@@ -24,3 +24,3 @@ var isBrowser = (typeof window !== 'undefined'); | ||
// use embedded worker.js | ||
var blob = new Blob([require('./lib/embeddedWorker')], {type: 'text/javascript'}); | ||
var blob = new Blob([require('./lib/generated/embeddedWorker')], {type: 'text/javascript'}); | ||
var url = window.URL.createObjectURL(blob); | ||
@@ -37,1 +37,7 @@ importScripts(url); | ||
}; | ||
/** | ||
* Create a promise. | ||
* @type {Promise} promise | ||
*/ | ||
exports.Promise = require('./lib/Promise'); |
@@ -1,2 +0,2 @@ | ||
var Promise = require('bluebird'), | ||
var Promise = require('./Promise'), | ||
WorkerHandler = require('./WorkerHandler'); | ||
@@ -82,14 +82,15 @@ | ||
var me = this; | ||
return new Promise(function (resolve, reject) { | ||
// add a new task to the queue | ||
me.tasks.push({ | ||
method: method, | ||
params: params, | ||
resolve: resolve, | ||
reject: reject | ||
}); | ||
var resolver = Promise.defer(); | ||
// trigger task execution | ||
me._next(); | ||
// add a new task to the queue | ||
this.tasks.push({ | ||
method: method, | ||
params: params, | ||
resolver: resolver | ||
}); | ||
// trigger task execution | ||
this._next(); | ||
return resolver.promise; | ||
}; | ||
@@ -135,18 +136,18 @@ | ||
// send the request to the worker | ||
worker.exec(task.method, task.params) | ||
.then(function (result) { | ||
task.resolve(result); | ||
me._next(); // trigger next task in the queue | ||
}) | ||
.catch(function (error) { | ||
task.reject(error); | ||
// check if the task is still pending (and not cancelled -> promise rejected) | ||
if (task.resolver.promise.pending) { | ||
// send the request to the worker | ||
worker.exec(task.method, task.params, task.resolver) | ||
.then(function () { | ||
me._next(); // trigger next task in the queue | ||
}) | ||
.catch(function () { | ||
// if the worker crashed and terminated, remove it from the pool | ||
if (worker.terminated) { | ||
me._removeWorker(worker); | ||
} | ||
// if the worker crashed and terminated, remove it from the pool | ||
if (worker.terminated) { | ||
me._removeWorker(worker); | ||
} | ||
me._next(); // trigger next task in the queue | ||
}); | ||
me._next(); // trigger next task in the queue | ||
}); | ||
} | ||
} | ||
@@ -206,2 +207,3 @@ } | ||
*/ | ||
// TODO: rename clear to terminate | ||
Pool.prototype.clear = function (force) { | ||
@@ -208,0 +210,0 @@ this.workers.forEach(function (worker) { |
@@ -1,3 +0,2 @@ | ||
var Promise = require('bluebird'), | ||
child_process = require('child_process'); | ||
var Promise = require('./Promise'); | ||
@@ -19,3 +18,3 @@ // determine environment | ||
// use embedded worker.js | ||
var blob = new Blob([require('./embeddedWorker')], {type: 'text/javascript'}); | ||
var blob = new Blob([require('./generated/embeddedWorker')], {type: 'text/javascript'}); | ||
return window.URL.createObjectURL(blob); | ||
@@ -60,3 +59,3 @@ } | ||
// on node.js, create a child process | ||
this.worker = child_process.fork(this.script); | ||
this.worker = require('child_process').fork(this.script); | ||
} | ||
@@ -73,13 +72,2 @@ | ||
// resolve the task's promise | ||
try { | ||
if (response.error) { | ||
task.reject(response.error); | ||
} | ||
else { | ||
task.resolve(response.result); | ||
} | ||
} | ||
catch (err) {} | ||
// test if we need to terminate | ||
@@ -90,2 +78,10 @@ if (me.terminating) { | ||
} | ||
// resolve the task's promise | ||
if (response.error) { | ||
task.resolver.reject(response.error); | ||
} | ||
else { | ||
task.resolver.resolve(response.result); | ||
} | ||
} | ||
@@ -100,3 +96,3 @@ }); | ||
if (me.processing.hasOwnProperty(id)) { | ||
me.processing[id].reject(error); | ||
me.processing[id].resolver.reject(error); | ||
} | ||
@@ -133,28 +129,50 @@ } | ||
* @param {Array} [params] | ||
* @param {{resolve: Function, reject: Function}} [resolver] | ||
* @return {Promise.<*, Error>} result | ||
*/ | ||
WorkerHandler.prototype.exec = function(method, params) { | ||
var me = this; | ||
WorkerHandler.prototype.exec = function(method, params, resolver) { | ||
if (!resolver) { | ||
resolver = Promise.defer(); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
// generate a unique id for the task | ||
var id = ++me.lastId; | ||
// generate a unique id for the task | ||
var id = ++this.lastId; | ||
// register a new task as being in progress | ||
me.processing[id] = { | ||
id: id, | ||
resolve: resolve, | ||
reject: reject | ||
}; | ||
// register a new task as being in progress | ||
this.processing[id] = { | ||
id: id, | ||
resolver: resolver | ||
}; | ||
// build a JSON-RPC request | ||
var request = { | ||
id: id, | ||
method: method, | ||
params: params | ||
}; | ||
// build a JSON-RPC request | ||
var request = { | ||
id: id, | ||
method: method, | ||
params: params | ||
}; | ||
if (this.terminated) { | ||
resolver.reject(new Error('Worker is terminated')); | ||
} | ||
else { | ||
// send the request to the worker | ||
me.worker.send(request); | ||
}); | ||
this.worker.send(request); | ||
} | ||
// on cancellation, force the worker to terminate | ||
var me = this; | ||
resolver.promise | ||
//.catch(Promise.CancellationError, function(error) { // TODO: not yet supported | ||
.catch(function (error) { | ||
if (error instanceof Promise.CancellationError || error instanceof Promise.TimeoutError) { | ||
// remove this task from the queue. It is already rejected (hence this | ||
// catch event), and else it will be rejected again when terminating | ||
delete me.processing[id]; | ||
// terminate worker | ||
me.terminate(true); | ||
} | ||
}); | ||
return resolver.promise; | ||
}; | ||
@@ -182,3 +200,3 @@ | ||
if (this.processing.hasOwnProperty(id)) { | ||
this.processing[id].reject(new Error('Worker terminated')); | ||
this.processing[id].resolver.reject(new Error('Worker terminated')); | ||
} | ||
@@ -185,0 +203,0 @@ } |
{ | ||
"name": "workerpool", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Offload tasks to a pool of workers on node.js and in the browser", | ||
@@ -25,4 +25,2 @@ "homepage": "https://github.com/josdejong/workerpool", | ||
"dependencies": { | ||
"bluebird": "^1.2.4", | ||
"promiscuous": "^0.6.0" | ||
}, | ||
@@ -29,0 +27,0 @@ "devDependencies": { |
# workerpool | ||
JavaScript is based upon a single event loop which handles one event at a time. All I/O operations are evented, asynchronous, and non-blocking, while the execution of non-I/O code itself is executed sequentially. Jeremy Epstein explains this clearly in the blog [Node.js itself is blocking, only its I/O is non-blocking](http://greenash.net.au/thoughts/2012/11/nodejs-itself-is-blocking-only-its-io-is-non-blocking/): | ||
JavaScript is based upon a single event loop which handles one event at a time. Jeremy Epstein [explains this clearly](http://greenash.net.au/thoughts/2012/11/nodejs-itself-is-blocking-only-its-io-is-non-blocking/): | ||
@@ -12,3 +12,3 @@ > In Node.js everything runs in parallel, except your code. | ||
For front-end processes, this is not a desired situation. | ||
Therefore, CPU intensive tasks should be offloaded from the main event loop onto dedicated *workers*. We can use [Web Workers](http://www.html5rocks.com/en/tutorials/workers/basics/) when in a browser environment, and [child processes](http://nodejs.org/api/child_process.html) when using node.js. Effectively, this results in an architecture which achieves concurrency by means of isolated processes and message passing. | ||
Therefore, CPU intensive tasks should be offloaded from the main event loop onto dedicated *workers*. In a browser environment, [Web Workers](http://www.html5rocks.com/en/tutorials/workers/basics/) can be used. In node.js, [child processes](http://nodejs.org/api/child_process.html) are available. Effectively, this results in an architecture which achieves concurrency by means of isolated processes and message passing. | ||
@@ -23,6 +23,8 @@ **workerpool** offers an easy way to create a pool of workers for both dynamically offloading computations as well as managing a pool of dedicated workers. Workers can be accessed via a natural, promise based proxy, as if they are available straight in the main application. | ||
- Easy to use | ||
- Can be used in both browser and node.js environment | ||
- Runs in the browser and on node.js | ||
- Dynamically offload functions to a worker | ||
- Workers are accessible via a proxy | ||
- Automatically restores crashed workers | ||
- Access workers via a proxy | ||
- Cancel running tasks | ||
- Set a timeout on tasks | ||
- Handles crashed workers | ||
@@ -134,3 +136,3 @@ | ||
### workerpool | ||
### pool | ||
@@ -159,2 +161,16 @@ A workerpool can be created using the function `workerpool.pool`: | ||
The functions `Pool.run`, `Pool.exec`, and the proxy functions all return a `Promise`. The promise has the following functions available: | ||
- `Promise.then(fn: Function.<result: *>)`<br> | ||
Get the result of the promise once resolve. | ||
- `Promise.catch(fn: Function.<error: Error>)`<br> | ||
Get the error of the promise when rejected. | ||
- `Promise.cancel()`<br> | ||
A running task can be cancelled. The worker executing the task is enforced to terminate immediately. | ||
The promise will be rejected with a `Promise.CancellationError`. | ||
- `Promise.timeout(delay: number)`<br> | ||
Cancel a running task when it is not resolved or rejected withing given delay in milliseconds. | ||
The worker executing the task is enforced to terminate immediately. | ||
The promise will be rejected with a `Promise.TimeoutError`. | ||
Example usage: | ||
@@ -230,2 +246,10 @@ | ||
## Sources of inspiration | ||
- https://github.com/learnboost/cluster | ||
- https://github.com/adambom/parallel.js | ||
- https://github.com/padolsey/operative | ||
- https://github.com/calvinmetcalf/catiline | ||
## Build | ||
@@ -232,0 +256,0 @@ |
var assert = require('assert'), | ||
Promise = require('bluebird'), | ||
Promise = require('../lib/Promise'), | ||
Pool = require('../lib/Pool'); | ||
@@ -148,2 +148,95 @@ | ||
it('should cancel a task', function (done) { | ||
var pool = new Pool({maxWorkers: 10}); | ||
function forever() { | ||
while (1 > 0) {} // runs forever | ||
} | ||
var promise = pool.run(forever) | ||
.then(function (result) { | ||
assert('promise should never resolve'); | ||
}) | ||
//.catch(Promise.CancellationError, function (err) { // TODO: not yet supported | ||
.catch(function (err) { | ||
assert(err instanceof Promise.CancellationError); | ||
assert.equal(pool.workers.length, 0); | ||
done(); | ||
}); | ||
// cancel the task | ||
setTimeout(function () { | ||
promise.cancel(); | ||
}, 0); | ||
}); | ||
it('should cancel a queued task', function (done) { | ||
var pool = new Pool({maxWorkers: 1}); | ||
var reachedTheEnd = false; | ||
function delayed() { | ||
var Promise = require('../lib/Promise'); | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
resolve(1); | ||
}, 0); | ||
}); | ||
} | ||
function one() { | ||
return 1; | ||
} | ||
var p1 = pool.run(delayed) | ||
.then(function (result) { | ||
assert.equal(result, 1); | ||
assert.equal(reachedTheEnd, true); | ||
assert.equal(pool.workers.length, 1); | ||
assert.equal(pool.tasks.length, 0); | ||
done(); | ||
}); | ||
assert.equal(pool.workers.length, 1); | ||
assert.equal(pool.tasks.length, 0); | ||
var p2 = pool.run(one); // will be queued | ||
assert.equal(pool.workers.length, 1); | ||
assert.equal(pool.tasks.length, 1); | ||
p2.cancel(); // cancel immediately | ||
assert.equal(pool.workers.length, 1); | ||
assert.equal(pool.tasks.length, 1); | ||
reachedTheEnd = true; | ||
}); | ||
// TODO: test whether a task in the queue can be neatly cancelled | ||
it('should timeout a task', function (done) { | ||
var pool = new Pool({maxWorkers: 10}); | ||
function forever() { | ||
while (1 > 0) {} // runs forever | ||
} | ||
var promise = pool.run(forever) | ||
.timeout(50) | ||
.then(function (result) { | ||
assert('promise should never resolve'); | ||
}) | ||
//.catch(Promise.CancellationError, function (err) { // TODO: not yet supported | ||
.catch(function (err) { | ||
assert(err instanceof Promise.TimeoutError); | ||
assert.equal(pool.workers.length, 0); | ||
done(); | ||
}); | ||
}); | ||
it('should handle crashed workers (1)', function (done) { | ||
@@ -150,0 +243,0 @@ var pool = new Pool({maxWorkers: 1}); |
var assert = require('assert'), | ||
Promise = require('bluebird'), | ||
Promise = require('../lib/Promise'), | ||
WorkerHandler = require('../lib/WorkerHandler'); | ||
@@ -91,5 +91,7 @@ | ||
handler.exec('run', [String(add), [2, 4]]) | ||
/* | ||
.then(function (result) { | ||
assert('Should not complete request'); | ||
}) | ||
*/ | ||
.catch(function (err) { | ||
@@ -110,3 +112,3 @@ assert.equal(err.toString(), 'Error: Worker terminated'); | ||
function asyncAdd(a, b) { | ||
var Promise = require('bluebird'); | ||
var Promise = require('../lib/Promise'); | ||
@@ -153,2 +155,54 @@ return new Promise(function (resolve, reject) { | ||
it('should cancel a task', function (done) { | ||
var handler = new WorkerHandler(); | ||
function forever() { | ||
while(1 > 0) { | ||
// whoops... infinite loop... | ||
} | ||
} | ||
var promise = handler.exec('run', [String(forever)]) | ||
.then(function (result) { | ||
assert('promise should never resolve'); | ||
}) | ||
//.catch(Promise.CancellationError, function (err) { // TODO: not yet supported | ||
.catch(function (err) { | ||
assert.equal(err.toString(), 'CancellationError: promise cancelled'); | ||
assert.equal(handler.worker, null); | ||
assert.equal(handler.terminated, true); | ||
done(); | ||
}); | ||
// cancel the task | ||
promise.cancel(); | ||
}); | ||
it('should timeout a task', function (done) { | ||
var handler = new WorkerHandler(); | ||
function forever() { | ||
while(1 > 0) { | ||
// whoops... infinite loop... | ||
} | ||
} | ||
handler.exec('run', [String(forever)]) | ||
.timeout(50) | ||
.then(function (result) { | ||
assert('promise should never resolve'); | ||
}) | ||
//.catch(Promise.TimeoutError, function (err) { // TODO: not yet supported | ||
.catch(function (err) { | ||
assert(err instanceof Promise.TimeoutError); | ||
assert.equal(handler.worker, null); | ||
assert.equal(handler.terminated, true); | ||
done(); | ||
}); | ||
}); | ||
it('should handle errors thrown by a worker (1)', function (done) { | ||
@@ -155,0 +209,0 @@ var handler = new WorkerHandler(); |
Sorry, the diff of this file is too big to display
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
29
303
140141
3048
2
2
10
- Removedbluebird@^1.2.4
- Removedpromiscuous@^0.6.0
- Removedbluebird@1.2.4(transitive)
- Removedpromiscuous@0.6.0(transitive)