futoin-asyncevent
Advanced tools
Comparing version 2.0.0 to 2.1.0
=== 2.1.0 (2018-06-09) === | ||
CHANGED: to use ActiveAsyncTool from AsyncSteps for event callback scheduling | ||
=== 2.0.0 (2018-06-06) === | ||
@@ -3,0 +6,0 @@ CHANGED: to use futoin-asyncsteps event loop |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["futoin-asyncevent"]=t():e.$asyncevent=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=18)}([function(e,t,n){"use strict";var r=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)};["ConnectError","CommError","UnknownInterface","NotSupportedVersion","NotImplemented","Unauthorized","InternalError","InvokerError","InvalidRequest","DefenseRejected","PleaseReauth","SecurityError","Timeout","LoopBreak","LoopCont"].forEach(function(e){return Object.defineProperty(r,e,{enumerable:!0,value:e})}),e.exports=r},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(0).NotImplemented,i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return r(e,[{key:"sync",value:function(e,t,n){e.error(o,"#sync() API")}}]),e}();e.exports=i},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var i=n(0),u=(i.InternalError,i.LoopCont),a=i.LoopBreak,c="undefined"==typeof Symbol?function(e){return e}:function(e){return Symbol(e)},s=c("_loop_term_label"),l=function(e,t,n,r,o){var i=t._async_tool,c=t.constructor;e.add(function(e){var t=e.state,l=void 0,f=[n,function(n,o){return function(e,t,n,r,o){if(t===u){var i=r[s];if(i&&i!==o)try{n.continue(i)}catch(e){}else e._root._handle_success()}else if(t===a){var c=r[s];if(c&&c!==o)try{n.break(c)}catch(e){}else n.state&&n._root._handle_success()}else try{n.error(t,r.error_info)}catch(e){}}(n,o,e,t,r)}],h=[function(t){o&&o()?e.state&&e._root._handle_success():_()},null],_=function(){var e=l=new c(t,i),n=e._queue;n.push(f),n.push(h),e.execute()};e.setCancel(function(e){l&&l.cancel()}),i.callImmediate(_)})},f=function(e,t,n,r,o){var i=0,u=n;l(e,t,function(e){r(e,i++)},o,function(){return i>=u})},h=function(e,t,n){var r=e.state;if(r){n instanceof Error?(r.last_exception=n,r.error_info=void 0,t._handle_error("PromiseReject")):(r.error_info=void 0,t._handle_error(n||"PromiseReject"))}},_=[];Object.freeze(_),e.exports=t={makeSym:c,loop:l,repeat:f,forEach:function(e,t,n,r,i){if(Array.isArray(n)){var u=n;f(e,t,u.length,function(e,t){r(e,t,u[t])},i)}else if("undefined"!=typeof Map&&n instanceof Map){var a=n.entries();l(e,t,function(e){var t=a.next();t.done&&e.break();var n=o(t.value,2),i=n[0],u=n[1];r(e,i,u)},i)}else{var c=n,s=Object.keys(c);f(e,t,s.length,function(e,t){r(e,s[t],c[s[t]])},i)}},LOOP_TERM_LABEL:s,as_await:function(e,t,n,r){var o=void 0,i=void 0;n.then(function(e){o?o._root._handle_success([e]):i=function(t){t._root._handle_success([e])}},function(e){o?h(o,t,e):(o=null,i=function(n){h(n,t,e)})}),e.add(function(e){i?i(e):(o=e,e.setCancel(function(){if(o){o=null;try{n.cancel()}catch(e){}}}))},r)},EMPTY_ARRAY:_};var v=function(){};t.noop,t.checkFunc=v,t.checkOnError=v;var p=new(function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return r(e,[{key:"push",value:function(){}}]),e}());Object.freeze(p),t.newExecStack=function(){return p}},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(1),i=n(0).DefenseRejected,u=function(e){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o._max=e,o._current=0,o._queue=[],o._timer=null,o._period_ms=n,o._max_queue=r,o}return function(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)}(t,o),r(t,[{key:"_lock",value:function(e){if(this._ensureTimer(),this._current>=this._max){var t=this._queue,n=this._max_queue;null!==n&&t.length>=n&&e.error(i,"Throttle queue limit"),t.push(e)}else this._current+=1,e._root._handle_success()}},{key:"_ensureTimer",value:function(){var e=this;this._timer||(this._timer=setInterval(function(){return e._resetPeriod()},this._period_ms))}},{key:"_resetPeriod",value:function(){this._current=0;var e=this._queue;if(!e.length)return clearInterval(this._timer),void(this._timer=null);for(var t=this._max,n=0;e.length&&n<t;){var r=e.shift();r.state&&(++n,r._root._handle_success())}this._current=n}},{key:"_cancel",value:function(e){var t=this._queue.indexOf(e);t>=0&&this._queue.splice(t,1)}},{key:"sync",value:function(e,t,n){var r=this,o=void 0;e.add(function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];o=n,e.setCancel(function(e){return r._cancel(e)}),r._lock(e)}),e._queue.push([function(e){e._root._next_args=o,e.add(t,n)},void 0])}}]),t}();e.exports=u},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(1),i=n(0).DefenseRejected,u=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r._max=e,r._locked=0,r._owners=new WeakMap,r._queue=[],r._max_queue=n,r}return function(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)}(t,o),r(t,[{key:"_lock",value:function(e){var t=e._root,n=this._owners,r=n.get(t);if(r)n.set(t,r+1),e._root._handle_success();else if(this._locked>=this._max){var o=this._queue,u=this._max_queue;null!==u&&o.length>=u&&e.error(i,"Mutex queue limit"),o.push(e)}else this._locked+=1,n.set(t,1),e._root._handle_success()}},{key:"_release",value:function(e){var t=e._root,n=this._owners,r=n.get(t);if(r){if(r>1)return void n.set(t,r-1);n.delete(t),this._locked<=0&&e.error("InternalError","Mutex must be in locked state"),this._locked-=1;for(var o=this._queue;o.length;){var i=o.shift();if(i.state){this._lock(i);break}}}else{var u=this._queue.indexOf(e);u>=0&&this._queue.splice(u,1)}}},{key:"sync",value:function(e,t,n){var r=this,o=void 0;e.add(function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];o=n,e.setCancel(function(e){return r._release(e)}),r._lock(e)});var i=e._queue;i.push([function(e){e.setCancel(function(e){return r._release(e)}),e._root._next_args=o,e.add(t,n)},void 0]),i.push([function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];r._release(e),e._root._handle_success(n)},void 0])}}]),t}();e.exports=u},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(2),i=o.checkFunc,u=o.checkOnError,a=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._root=t,this._as=n,this._queue=[],this._psteps=[],this._complete_count=0}return r(e,[{key:"add",value:function(e,t){return i(this,e),u(this,t),this._queue.push([e,t]),this}},{key:"_complete",value:function(){this._complete_count+=1,this._complete_count===this._psteps.length&&(this._as._root._handle_success(),this._cleanup())}},{key:"_error",value:function(e,t){try{this._as.error(e,t)}catch(e){}}},{key:"executeParallel",value:function(t){var n=this,r=this._queue,o=this._root;if(o!==t._root){var i=new e(t._root,t);return i._queue.push.apply(i._queue,r),void i.executeParallel(t)}if(this._as=t,r.length){t.setCancel(function(){return n.cancel()});var u=this._psteps,a=function(e){return n._complete()},c=function(e,t){return n._error(t,e.state.error_info)},s=o.constructor;r.forEach(function(e){var n=new s(t.state,o._async_tool);n.add(function(t){return t.add(e[0],e[1])},c),n._queue.push([a,void 0]),u.push(n)}),u.forEach(function(e){return e.execute()})}else this._complete()}},{key:"cancel",value:function(){this._psteps.forEach(function(e){return e.cancel()}),this._cleanup()}},{key:"isAsyncSteps",value:function(){return!0}},{key:"_cleanup",value:function(){this._root=null,this._as=null,this._psteps=null}}]),e}();e.exports=a},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(7),i=n(0).InternalError,u=n(10),a=n(5),c=n(2),s=c.checkFunc,l=c.checkOnError,f=c.noop,h=c.loop,_=c.repeat,v=c.forEach,p=c.as_await,y=c.EMPTY_ARRAY,d=c.newExecStack,m=f||function(e){e._stack.length>0&&e.error(i,"Top level add in execution")},b=f||function(e,t,n){m(e),s(e,t),l(e,n)},w=function(){function e(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),null===n&&(n=function(){return this.state}),this.state=n,this._queue=[],this._stack=[],this._exec_stack=d(),this._in_exec=!1,this._exec_event=null,this._next_args=y,this._async_tool=r;var i=r.callImmediate,u=function(){return t.execute()};this._scheduleExecute=function(){t._exec_event=i(u)}}return r(e,[{key:"add",value:function(e,t){return b(this,e,t),this._queue.push([e,t]),this}},{key:"parallel",value:function(e){var t=new a(this,this);return this.add(function(e){return t.executeParallel(e)},e),t}},{key:"sync",value:function(e,t,n){return b(this,t,n),e.sync(this,t,n),this}},{key:"error",value:function(e,t){throw this.state.error_info=t,this._in_exec||this._handle_error(e),new Error(e)}},{key:"copyFrom",value:function(e){this._queue.push.apply(this._queue,e._queue);var t=e.state,n=this.state;for(var r in t)r in n||(n[r]=t[r]);return this}},{key:"_handle_success",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:y,t=this._stack;t.length||this.error(i,"Invalid success completion"),this._next_args=e;for(var n=t[t.length-1];;){var r=n._limit_event;if(r&&(this._async_tool.cancelCall(r),n._limit_event=null),n._cleanup(),t.pop(),!t.length)break;if((n=t[t.length-1])._queue.length)break}(t.length||this._queue.length)&&this._scheduleExecute()}},{key:"_handle_error",value:function(e){if(this._exec_event)this.cancel();else{this._next_args=y;var t=this._stack,n=this._exec_stack;for(this.state.async_stack=n;t.length;t.pop()){var r=t[t.length-1],o=r._limit_event,i=r._on_cancel,u=r._on_error;if(o&&(this._async_tool.cancelCall(o),r._limit_event=null),i&&(i.call(null,r),r._on_cancel=null),u){var a=t.length;r._queue=null;try{if(this._in_exec=!0,u.call(null,r,e),a!==t.length)return;if(null!==r._queue)return n.push(u),r._on_error=null,void this._scheduleExecute()}catch(t){this.state.last_exception=t,e=t.message}finally{this._in_exec=!1}}r._cleanup()}this._queue=[]}}},{key:"cancel",value:function(){this._next_args=y;var e=this._exec_event;e&&(this._async_tool.cancelImmediate(e),this._exec_event=null);for(var t=this._stack,n=this._async_tool;t.length;){var r=t.pop(),o=r._limit_event,i=r._on_cancel;o&&(n.cancelCall(o),r._limit_event=null),i&&(i.call(null,r),r._on_cancel=null),r._cleanup()}return this._queue=[],this}},{key:"execute",value:function(){this._exec_event=null;var e=this._stack,t=void 0;if((t=e.length?e[e.length-1]._queue:this._queue).length){var n=t.shift(),r=n[0];if(r){var o=new u(this),i=[o],a=this._next_args,c=a.length;if(c>0){for(var s=0;s<c;++s)i.push(a[s]);this._next_args=y}try{o._on_error=n[1],e.push(o),this._exec_stack.push(r);var l=e.length;this._in_exec=!0,r.apply(void 0,i),l===e.length&&(null!==o._queue?this._scheduleExecute():null!==o._limit_event||null!==o._on_cancel||o._wait_external||this._handle_success(this._next_args))}catch(e){this._in_exec=!1,this.state.last_exception=e,this._handle_error(e.message)}finally{this._in_exec=!1}return this}this._handle_success()}}},{key:"loop",value:function(e,t){return b(this,e),h(this,this,e,t),this}},{key:"repeat",value:function(e,t,n){return b(this,t),_(this,this,e,t,n),this}},{key:"forEach",value:function(e,t,n){return b(this,t),v(this,this,e,t,n),this}},{key:"successStep",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];m(this);var r=this._queue;return r.length>0?r.push([function(e){return e._root._handle_success(t)},void 0]):this._next_args=t,this}},{key:"await",value:function(e,t){return m(this),p(this,this,e,t),this}},{key:"isAsyncSteps",value:function(){return!0}}]),e}();e.exports=w},function(e,t,n){"use strict";if(t=e.exports={},"undefined"==typeof setImmediate){t.callLater=function(e,t){return setTimeout(e,t)},t.cancelCall=function(e){return clearTimeout(e)};var r=[],o=window.performance,i=null,u=function e(){i=null;for(var t=o.now()+100,n=1e4;n>0&&r.length;--n){var u=r.shift();try{u()}catch(t){throw i=setTimeout(e,0),t}if(o.now()>=t)break}r.length&&(i=setTimeout(e,0))};t.callImmediate=function(e){var t=function(){return e()};return r.push(t),i||(i=setTimeout(u,0)),t},t.cancelImmediate=function(e){var t=r.indexOf(e);t>=0&&r.splice(t,1)}}else t.callLater=function(e,t){return setTimeout(e,t)},t.cancelCall=function(e){clearTimeout(e)},t.callImmediate=function(e){return setImmediate(e)},t.cancelImmediate=function(e){clearImmediate(e)}},function(e,t,n){"use strict";var r=n(6);e.exports=function(e,t){return function(n){var o=this,i=new r;i.add(function(n){n.add(function(n){e.call(o,n),t&&n.add(function(e){return e.error("NegativeTestMustThrow")})},t)},function(e,t){console.log("ERROR: "+t+" ("+e.state.error_info+")"),n(e.state.last_exception||new Error("Generic Fail"))}),i.add(function(e){return n()}),i.execute()}}},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(1),i=n(4),u=n(3),a=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n._mutex=new i(e.concurrent||1,e.max_queue||0),n._throttle=new u(e.rate||1,e.period_ms||1e3,e.burst||0),n}return function(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)}(t,o),r(t,[{key:"sync",value:function(e,t,n){var r=this;e.sync(this._mutex,function(e){for(var o=arguments.length,i=Array(o>1?o-1:0),u=1;u<o;u++)i[u-1]=arguments[u];e._root._next_args=i,e.sync(r._throttle,t,n)})}}]),t}();e.exports=a},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(5),i=n(0),u=i.InternalError,a=i.Timeout,c=i.LoopBreak,s=i.LoopCont,l=n(2),f=l.checkFunc,h=l.checkOnError,_=l.noop,v=l.loop,p=l.repeat,y=l.forEach,d=l.LOOP_TERM_LABEL,m=l.as_await,b=_||function(e){var t=e._root;if(t){var n=t._stack;if(n){if(n[n.length-1]===e)return;t.error(u,"Invalid call (sanity check)")}}throw new Error("InternalError: Unexpected call, object is out of service")},w=_||function(e,t,n){b(e),f(e,t),h(e,n)},x=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._root=t,this.state=t.state,this._queue=null,this._on_error=null,this._on_cancel=null,this._limit_event=null,this._wait_external=!1}return r(e,[{key:"add",value:function(e,t){w(this,e,t);var n=this._queue;return null===n&&(n=[],this._queue=n),n.push([e,t]),this}},{key:"parallel",value:function(e){var t=new o(this._root,this);return this.add(function(e){return t.executeParallel(e)},e),t}},{key:"success",value:function(){b(this),null!==this._queue&&this.error(u,"Invalid success() call");for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];this._root._handle_success(t)}},{key:"error",value:function(e,t){b(this),this._root.error(e,t)}},{key:"setTimeout",value:function(e){var t=this;b(this);var n=this._root._async_tool;return null!==this._limit_event&&n.cancelCall(this._limit_event),this._limit_event=n.callLater(function(){t._limit_event=null;try{t._root.error(a)}catch(e){}},e),this}},{key:"setCancel",value:function(e){return this._on_cancel=e,this}},{key:"waitExternal",value:function(){return this._wait_external=!0,this}},{key:"copyFrom",value:function(e){if(b(this),e._queue.length){var t=this._queue;null===t&&(t=[],this._queue=t),t.push.apply(t,e._queue)}var n=e.state,r=this.state;for(var o in n)void 0===r[o]&&(r[o]=n[o]);return this}},{key:"loop",value:function(e,t){return w(this,e),v(this,this._root,e,t),this}},{key:"repeat",value:function(e,t,n){return w(this,t),p(this,this._root,e,t,n),this}},{key:"forEach",value:function(e,t,n){return w(this,t),y(this,this._root,e,t,n),this}},{key:"break",value:function(e){b(this),this.state[d]=e,this._root.error(c)}},{key:"continue",value:function(e){b(this),this.state[d]=e,this._root.error(s)}},{key:"successStep",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];b(this);var r=this._queue;return r&&r.length?r.push([function(e){return e._root._handle_success(t)},void 0]):this._root._next_args=t,this}},{key:"await",value:function(e,t){return b(this),m(this,this._root,e,t),this}},{key:"sync",value:function(e,t,n){return w(this,t,n),e.sync(this,t,n),this}},{key:"isAsyncSteps",value:function(){return!0}},{key:"_cleanup",value:function(){this._root=null,this._queue=null,this._on_error=null,this._on_cancel=null,this.state=null}}]),e}();e.exports=x},function(e,t){(function(){var t,n,r,o,i,u;"undefined"!=typeof performance&&null!==performance&&performance.now?e.exports=function(){return performance.now()}:"undefined"!=typeof process&&null!==process&&process.hrtime?(e.exports=function(){return(t()-i)/1e6},n=process.hrtime,o=(t=function(){var e;return 1e9*(e=n())[0]+e[1]})(),u=1e9*process.uptime(),i=o-u):Date.now?(e.exports=function(){return Date.now()-r},r=Date.now()):(e.exports=function(){return(new Date).getTime()-r},r=(new Date).getTime())}).call(this)},function(e,t,n){"use strict";var r=n(11),o=[];(t=e.exports={}).callLater=function(e,t){var n=1e3*r();t&&(n+=t);for(var i={f:e,t:n},u=0;u<o.length;++u)if(o[u].t>n)return void o.splice(u,0,i);return o.push(i),i},t.cancelCall=function(e){var t=o.indexOf(e);t>=0&&o.splice(t,1)},t.nextEvent=function(){o.shift().f()},t.hasEvents=function(){return o.length>0},t.getEvents=function(){return o},t.resetEvents=function(){o.splice(0,o.length)},t.run=function(){for(;this.hasEvents();)this.nextEvent()},t.callImmediate=t.callLater,t.cancelImmediate=t.cancelCall},function(e,t,n){"use strict";var r=n(7),o=n(12),i=n(0),u=n(6);(t=e.exports=function(){return new u(null,t.ActiveAsyncTool)}).ActiveAsyncTool=r,t.AsyncTool=r,t.AsyncToolTest=o,t.FutoInError=i,t.Errors=i,t.AsyncSteps=u,t.installAsyncToolTest=function(e){t.ActiveAsyncTool=!1===e?r:o},t.assertAS=function(e){try{if(e.isAsyncSteps())return}catch(e){}throw new Error("Not an instance of AsyncSteps: "+e)}},function(e,t,n){"use strict";(t=e.exports=n(13)).ISync=n(1),t.Mutex=n(4),t.Throttle=n(3),t.Limiter=n(9),t.testcase=n(8)},function(e,t,n){"use strict";!function(t){var r=t.FutoIn||t.futoin||{};if(void 0===r.AsyncSteps){var o=n(14);t.$as=o,r.$as=o,t.FutoInError=o.FutoInError,r.AsyncSteps=o.AsyncSteps,t.FutoIn=r,t.futoin=r}e.exports=r.$as}(window)},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var i=n(15).AsyncTool.callImmediate,u=Symbol("FutoIn Event Emitter"),a="_evt_",c="_evtonce_",s=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._max=n;var r=!0,o=!1,i=void 0;try{for(var u,s=t[Symbol.iterator]();!(r=(u=s.next()).done);r=!0){var l=u.value;this[""+a+l]=[],this[""+c+l]=[]}}catch(e){o=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(o)throw i}}}return r(e,[{key:"on",value:function(e,t){try{var n=this[""+a+e];n.length===this._max&&console.warn("Hitting max handler limit for: "+e),n.push(t)}catch(t){throw new Error("Unknown event: "+e)}}},{key:"once",value:function(e,t){try{var n=this[""+c+e];n.length===this._max&&console.warn("Hitting max once handler limit for: "+e),n.push(t)}catch(t){throw new Error("Unknown event: "+e)}}},{key:"off",value:function(e,t){try{var n=""+a+e;this[n]=this[n].filter(function(e){return e!==t});var r=""+c+e;this[r]=this[r].filter(function(e){return e!==t})}catch(t){throw new Error("Unknown event: "+e)}}},{key:"emit",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];try{var o=function(e){i(function(){return e.apply(void 0,n)})},u=!0,s=!1,l=void 0;try{for(var f,h=this[""+a+e][Symbol.iterator]();!(u=(f=h.next()).done);u=!0){o(f.value)}}catch(e){s=!0,l=e}finally{try{!u&&h.return&&h.return()}finally{if(s)throw l}}var _=this[""+c+e];if(_.length>0){var v=function(e){i(function(){return e.apply(void 0,n)})},p=!0,y=!1,d=void 0;try{for(var m,b=_[Symbol.iterator]();!(p=(m=b.next()).done);p=!0){v(m.value)}}catch(e){y=!0,d=e}finally{try{!p&&b.return&&b.return()}finally{if(y)throw d}}this[""+c+e]=[]}}catch(t){throw new Error("Unknown event: "+e)}}}],[{key:Symbol.hasInstance,value:function(t){return void 0!==t[u]||t.constructor===e}},{key:"attach",value:function(t,n){var r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:8,s=t[u];if(void 0===s){var l=new e(n,i);Object.defineProperties(t,(o(r={},u,{configurable:!1,enumerable:!1,writable:!1,value:l}),o(r,"on",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return l.on(e,t)}}),o(r,"off",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return l.off(e,t)}}),o(r,"once",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return l.once(e,t)}}),o(r,"emit",{configurable:!1,enumerable:!1,writable:!1,value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return l.emit.apply(l,[e].concat(n))}}),r))}else{s._max=i;var f=!0,h=!1,_=void 0;try{for(var v,p=n[Symbol.iterator]();!(f=(v=p.next()).done);f=!0){var y=v.value;if(""+a+y in s)throw new Error('Event "'+y+'" has been already registered!');s[""+a+y]=[],s[""+c+y]=[]}}catch(e){h=!0,_=e}finally{try{!f&&p.return&&p.return()}finally{if(h)throw _}}}}},{key:"setMaxListeners",value:function(e,t){e[u]._max=t}},{key:"SYM_EVENT_EMITTER",get:function(){return u}}]),e}();e.exports=s},function(e,t,n){"use strict";var r=n(16),o=r.attach;o.EventEmitter=r,e.exports=o},function(e,t,n){"use strict";!function(t){var r=t.FutoIn||t.futoin||{};if(void 0===r.$asyncevent){var o=n(17);t.$asyncevent=o,r.$asyncevent=o,r.EventEmitter=o.EventEmitter,t.FutoIn=r,t.futoin=r}e.exports=r.$asyncevent}(window)}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["futoin-asyncevent"]=t():e.$asyncevent=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=18)}([function(e,t,n){"use strict";var r=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)};["ConnectError","CommError","UnknownInterface","NotSupportedVersion","NotImplemented","Unauthorized","InternalError","InvokerError","InvalidRequest","DefenseRejected","PleaseReauth","SecurityError","Timeout","LoopBreak","LoopCont"].forEach(function(e){return Object.defineProperty(r,e,{enumerable:!0,value:e})}),e.exports=r},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(0).NotImplemented,i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return r(e,[{key:"sync",value:function(e,t,n){e.error(o,"#sync() API")}}]),e}();e.exports=i},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&a.return&&a.return()}finally{if(o)throw i}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var i=n(0),u=(i.InternalError,i.LoopCont),a=i.LoopBreak,c="undefined"==typeof Symbol?function(e){return e}:function(e){return Symbol(e)},s=c("_loop_term_label"),l=function(e,t,n,r,o){o&&o()||e.add(function(e){var i=e.state,c=t._exec_stack,l=c.length,f=[n,function(t,n){return function(e,t,n,r,o){if(t===u){var i=r[s];i&&i!==o||(r.last_exception=null,e._root._handle_success())}else if(t===a){var c=r[s];c&&c!==o||(r.last_exception=null,n._queue.length=0,e._root._handle_success())}}(t,n,e,i,r)}],h=[function(e){o&&o()||(c.length=l,_())},null],_=function(){e._queue=[f,h]};_()})},f=function(e,t,n,r,o){var i=0,u=n;l(e,t,function(e){r(e,i++)},o,function(){return i>=u})},h=[];Object.freeze(h);var _=function(){};e.exports=t={noop:_,makeSym:c,loop:l,repeat:f,forEach:function(e,t,n,r,i){if(Array.isArray(n)){var u=n;f(e,t,u.length,function(e,t){r(e,t,u[t])},i)}else if("undefined"!=typeof Map&&n instanceof Map){var a=n.entries();l(e,t,function(e){var t=a.next();t.done&&e.break();var n=o(t.value,2),i=n[0],u=n[1];r(e,i,u)},i)}else{var c=n,s=Object.keys(c);f(e,t,s.length,function(e,t){r(e,s[t],c[s[t]])},i)}},LOOP_TERM_LABEL:s,as_await:function(e,t,n,r){var o=void 0,i=void 0;n.then(function(e){o?o._root._handle_success([e]):i=function(t){t._root._handle_success([e])}},function(e){o?function(e,t,n){var r=e.state;r&&(e._on_cancel=null,n instanceof Error?(r.last_exception=n,r.error_info=void 0,t._handle_error("PromiseReject")):(r.last_exception=null,r.error_info=void 0,t._handle_error(n||"PromiseReject")))}(o,t,e):(o=null,i=e instanceof Error?function(){throw e}:function(t){return t.error(e||"PromiseReject")})}),e.add(function(e){i?i(e):(o=e,e.setCancel(function(){if(o){o=null;try{n.cancel()}catch(e){}}}))},r)},EMPTY_ARRAY:h},t.isProduction=!0,t.checkFunc=_,t.checkOnError=_;var v=new(function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return r(e,[{key:"push",value:function(){}},{key:"length",get:function(){return 0},set:function(e){}}]),e}());Object.freeze(v),t.newExecStack=function(){return v}},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(1),i=n(0).DefenseRejected,u=function(e){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o._max=e,o._current=0,o._queue=[],o._timer=null,o._period_ms=n,o._max_queue=r,o}return function(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)}(t,o),r(t,[{key:"_lock",value:function(e){if(this._ensureTimer(),this._current>=this._max){var t=this._queue,n=this._max_queue;null!==n&&t.length>=n&&e.error(i,"Throttle queue limit"),t.push(e)}else this._current+=1,e._root._handle_success()}},{key:"_ensureTimer",value:function(){var e=this;this._timer||(this._timer=setInterval(function(){return e._resetPeriod()},this._period_ms))}},{key:"_resetPeriod",value:function(){this._current=0;var e=this._queue;if(!e.length)return clearInterval(this._timer),void(this._timer=null);for(var t=this._max,n=0;e.length&&n<t;){var r=e.shift();r.state&&(++n,r._root._handle_success())}this._current=n}},{key:"_cancel",value:function(e){var t=this._queue.indexOf(e);t>=0&&this._queue.splice(t,1)}},{key:"sync",value:function(e,t,n){var r=this,o=void 0;e.add(function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];o=n,e.setCancel(function(e){return r._cancel(e)}),r._lock(e)}),e._queue.push([function(e){e._root._next_args=o,e.add(t,n)},void 0])}}]),t}();e.exports=u},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(1),i=n(0).DefenseRejected,u=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return r._max=e,r._locked=0,r._owners=new WeakMap,r._queue=[],r._max_queue=n,r}return function(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)}(t,o),r(t,[{key:"_lock",value:function(e){var t=e._root,n=this._owners,r=n.get(t);if(r)n.set(t,r+1),e._root._handle_success();else if(this._locked>=this._max){var o=this._queue,u=this._max_queue;null!==u&&o.length>=u&&e.error(i,"Mutex queue limit"),o.push(e)}else this._locked+=1,n.set(t,1),e._root._handle_success()}},{key:"_release",value:function(e){var t=e._root,n=this._owners,r=n.get(t);if(r){if(r>1)return void n.set(t,r-1);n.delete(t),this._locked<=0&&e.error("InternalError","Mutex must be in locked state"),this._locked-=1;for(var o=this._queue;o.length;){var i=o.shift();if(i.state){this._lock(i);break}}}else{var u=this._queue.indexOf(e);u>=0&&this._queue.splice(u,1)}}},{key:"sync",value:function(e,t,n){var r=this,o=void 0;e.add(function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];o=n,e.setCancel(function(e){return r._release(e)}),r._lock(e)});var i=e._queue;i.push([function(e){e.setCancel(function(e){return r._release(e)}),e._root._next_args=o,e.add(t,n)},void 0]),i.push([function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];r._release(e),e._root._handle_success(n)},void 0])}}]),t}();e.exports=u},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(2),i=o.checkFunc,u=o.checkOnError,a=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._root=t,this._as=n,this._queue=[],this._psteps=[],this._complete_count=0}return r(e,[{key:"add",value:function(e,t){return i(this,e),u(this,t),this._queue.push([e,t]),this}},{key:"_complete",value:function(){this._complete_count+=1,this._complete_count===this._psteps.length&&(this._as._root._handle_success(),this._cleanup())}},{key:"_error",value:function(e,t){try{this._as.error(e,t)}catch(e){}}},{key:"executeParallel",value:function(t){var n=this,r=this._queue,o=this._root;if(o!==t._root){var i=new e(t._root,t);return i._queue.push.apply(i._queue,r),void i.executeParallel(t)}if(this._as=t,r.length){t.setCancel(function(){return n.cancel()});var u=this._psteps,a=function(e){return n._complete()},c=function(e,t){return n._error(t,e.state.error_info)},s=o.constructor;r.forEach(function(e){var n=new s(t.state,o._async_tool);n.add(function(t){return t.add(e[0],e[1])},c),n._queue.push([a,void 0]),u.push(n)}),u.forEach(function(e){return e.execute()})}else this._complete()}},{key:"cancel",value:function(){this._psteps.forEach(function(e){return e.cancel()}),this._cleanup()}},{key:"isAsyncSteps",value:function(){return!0}},{key:"_cleanup",value:function(){this._root=null,this._as=null,this._psteps=null}}]),e}();e.exports=a},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(7),i=n(0).InternalError,u=n(10),a=n(5),c=n(2),s=c.isProduction,l=c.checkFunc,f=c.checkOnError,h=c.noop,_=c.loop,v=c.repeat,p=c.forEach,y=c.as_await,d=c.EMPTY_ARRAY,m=c.newExecStack,b=s?h:function(e){e._stack.length>0&&e.error(i,"Top level add in execution")},w=s?h:function(e,t,n){b(e),l(e,t),f(e,n)},x=100,g=x,k=function(e){e._post_exec=h,e.execute()},E=function(){function e(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),null===n&&(n=function(){return this.state}),this.state=n,this._queue=[],this._stack=[],this._exec_stack=m(),this._in_exec=!1,this._post_exec=h,this._exec_event=null,this._next_args=d,this._async_tool=r;var i=r.callImmediate,u=function(){g=x,t._exec_event=null,t.execute()};this._scheduleExecute=function(){--g<=0?t._exec_event=i(u):t._in_exec?t._post_exec=k:t.execute()}}return r(e,[{key:"add",value:function(e,t){return w(this,e,t),this._queue.push([e,t]),this}},{key:"parallel",value:function(e){var t=new a(this,this);return this.add(function(e){return t.executeParallel(e)},e),t}},{key:"sync",value:function(e,t,n){return w(this,t,n),e.sync(this,t,n),this}},{key:"error",value:function(e,t){throw this.state.error_info=t,this._in_exec||this._handle_error(e),new Error(e)}},{key:"copyFrom",value:function(e){this._queue.push.apply(this._queue,e._queue);var t=e.state,n=this.state;for(var r in t)r in n||(n[r]=t[r]);return this}},{key:"_handle_success",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:d,t=this._stack;t.length||this.error(i,"Invalid success completion"),this._next_args=e;for(var n=t[t.length-1];;){var r=n._limit_event;if(r&&(this._async_tool.cancelCall(r),n._limit_event=null),n._cleanup(),t.pop(),!t.length)break;if((n=t[t.length-1])._queue.length)break}(t.length||this._queue.length)&&this._scheduleExecute()}},{key:"_handle_error",value:function(e){if(this._exec_event)this.cancel();else{this._next_args=d;var t=this._stack,n=this._exec_stack;this.state.async_stack=n;for(var r=this._in_exec,o=!0;t.length;){var i=t[t.length-1],u=i._limit_event,a=i._on_cancel,c=i._on_error;if(u&&(this._async_tool.cancelCall(u),i._limit_event=null),a&&(a.call(null,i),i._on_cancel=null),c){var s=t.length;i._queue=null,i._on_error=null,n.push(c);try{if(this._in_exec=!0,c.call(null,i,e),s!==t.length){o=!1;break}if(null!==i._queue){o=!1,this._scheduleExecute();break}}catch(t){this.state.last_exception=t,e=t.message}finally{this._in_exec=r}}i._cleanup(),t.pop()}o?this._queue=[]:r||this._post_exec(this)}}},{key:"cancel",value:function(){this._next_args=d;var e=this._exec_event;e&&(this._async_tool.cancelImmediate(e),this._exec_event=null);for(var t=this._stack,n=this._async_tool;t.length;){var r=t.pop(),o=r._limit_event,i=r._on_cancel;o&&(n.cancelCall(o),r._limit_event=null),i&&(i.call(null,r),r._on_cancel=null),r._cleanup()}return this._queue=[],this}},{key:"execute",value:function(){var e=this._stack,t=void 0;if((t=e.length?e[e.length-1]._queue:this._queue).length){var n=t.shift(),r=n[0];if(r){var o=new u(this),i=[o],a=this._next_args,c=a.length;if(c>0){for(var s=0;s<c;++s)i.push(a[s]);this._next_args=d}try{o._on_error=n[1],e.push(o),this._exec_stack.push(r);var l=e.length;this._in_exec=!0,r.apply(void 0,i),l===e.length&&(null!==o._queue?this._scheduleExecute():null!==o._limit_event||null!==o._on_cancel||o._wait_external||this._handle_success(this._next_args))}catch(e){this.state.last_exception=e,this._handle_error(e.message)}finally{this._in_exec=!1}return this._post_exec(this),this}this._handle_success()}}},{key:"loop",value:function(e,t){return w(this,e),_(this,this,e,t),this}},{key:"repeat",value:function(e,t,n){return w(this,t),v(this,this,e,t,n),this}},{key:"forEach",value:function(e,t,n){return w(this,t),p(this,this,e,t,n),this}},{key:"successStep",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];b(this);var r=this._queue;return r.length>0?r.push([function(e){return e._root._handle_success(t)},void 0]):this._next_args=t,this}},{key:"await",value:function(e,t){return b(this),y(this,this,e,t),this}},{key:"promise",value:function(){var e=this;return b(this),new Promise(function(t,n){var r=e._queue;e._queue=[[function(e){e._queue=r},function(e,t){n(new Error(t))}],[function(e,n){t(n)},void 0]],e.execute()})}},{key:"isAsyncSteps",value:function(){return!0}}]),e}();e.exports=E},function(e,t,n){"use strict";if(t=e.exports={},"undefined"==typeof setImmediate){t.callLater=function(e,t){return setTimeout(e,t)},t.cancelCall=function(e){return clearTimeout(e)},window._FutoInEventLoopQueue=window._FutoInEventLoopQueue||[];var r=window._FutoInEventLoopQueue,o=window.performance,i=null,u=function(){i&&clearTimeout(i),i=setTimeout(a,0)},a=function(){i=null;for(var e=o.now()+10;r.length;){var t=r.shift();try{t()}catch(e){throw u(),e}if(o.now()>=e){u();break}}};t.callImmediate=function(e){r.length||u();var t=function(){return e()};return r.push(t),t},t.cancelImmediate=function(e){var t=r.indexOf(e);t>=0&&r.splice(t,1)}}else t.callLater=function(e,t){return setTimeout(e,t)},t.cancelCall=function(e){clearTimeout(e)},t.callImmediate=function(e){return setImmediate(e)},t.cancelImmediate=function(e){clearImmediate(e)}},function(e,t,n){"use strict";var r=n(6);e.exports=function(e,t){return function(n){var o=this,i=new r;i.add(function(n){n.add(function(n){e.call(o,n),t&&n.add(function(e){return e.error("NegativeTestMustThrow")})},t)},function(e,t){console.log("ERROR: "+t+" ("+e.state.error_info+")"),n(e.state.last_exception||new Error("Generic Fail"))}),i.add(function(e){return n()}),i.execute()}}},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(1),i=n(4),u=n(3),a=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n._mutex=new i(e.concurrent||1,e.max_queue||0),n._throttle=new u(e.rate||1,e.period_ms||1e3,e.burst||0),n}return function(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)}(t,o),r(t,[{key:"sync",value:function(e,t,n){var r=this;e.sync(this._mutex,function(e){for(var o=arguments.length,i=Array(o>1?o-1:0),u=1;u<o;u++)i[u-1]=arguments[u];e._root._next_args=i,e.sync(r._throttle,t,n)})}}]),t}();e.exports=a},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=n(5),i=n(0),u=i.InternalError,a=i.Timeout,c=i.LoopBreak,s=i.LoopCont,l=n(2),f=l.isProduction,h=l.checkFunc,_=l.checkOnError,v=l.noop,p=l.loop,y=l.repeat,d=l.forEach,m=l.LOOP_TERM_LABEL,b=l.as_await,w=f?v:function(e){var t=e._root;if(t){var n=t._stack;if(n){if(n[n.length-1]===e)return;t.error(u,"Invalid call (sanity check)")}}throw new Error("InternalError: Unexpected call, object is out of service")},x=f?v:function(e,t,n){w(e),h(e,t),_(e,n)},g=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._root=t,this.state=t.state,this._queue=null,this._on_error=null,this._on_cancel=null,this._limit_event=null,this._wait_external=!1}return r(e,[{key:"add",value:function(e,t){x(this,e,t);var n=[e,t],r=this._queue;return r?r.push(n):this._queue=[n],this}},{key:"parallel",value:function(e){var t=new o(this._root,this);return this.add(function(e){return t.executeParallel(e)},e),t}},{key:"success",value:function(){w(this),null!==this._queue&&this.error(u,"Invalid success() call");for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];this._root._handle_success(t)}},{key:"error",value:function(e,t){w(this),this._root.error(e,t)}},{key:"setTimeout",value:function(e){var t=this;w(this);var n=this._root._async_tool;return null!==this._limit_event&&n.cancelCall(this._limit_event),this._limit_event=n.callLater(function(){t._limit_event=null;var e=t.state;e.error_info=void 0,e.last_exception=null,t._root._handle_error(a)},e),this}},{key:"setCancel",value:function(e){return this._on_cancel=e,this}},{key:"waitExternal",value:function(){return this._wait_external=!0,this}},{key:"copyFrom",value:function(e){if(w(this),e._queue.length){var t=this._queue;null===t&&(t=[],this._queue=t),t.push.apply(t,e._queue)}var n=e.state,r=this.state;for(var o in n)void 0===r[o]&&(r[o]=n[o]);return this}},{key:"loop",value:function(e,t){return x(this,e),p(this,this._root,e,t),this}},{key:"repeat",value:function(e,t,n){return x(this,t),y(this,this._root,e,t,n),this}},{key:"forEach",value:function(e,t,n){return x(this,t),d(this,this._root,e,t,n),this}},{key:"break",value:function(e){w(this),this.state[m]=e,this._root.error(c)}},{key:"continue",value:function(e){w(this),this.state[m]=e,this._root.error(s)}},{key:"successStep",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];w(this);var r=this._queue;return r&&r.length?r.push([function(e){return e._root._handle_success(t)},void 0]):this._root._next_args=t,this}},{key:"await",value:function(e,t){return w(this),b(this,this._root,e,t),this}},{key:"sync",value:function(e,t,n){return x(this,t,n),e.sync(this,t,n),this}},{key:"isAsyncSteps",value:function(){return!0}},{key:"_cleanup",value:function(){this._root=null,this.state=null}}]),e}();e.exports=g},function(e,t){(function(){var t,n,r,o,i,u;"undefined"!=typeof performance&&null!==performance&&performance.now?e.exports=function(){return performance.now()}:"undefined"!=typeof process&&null!==process&&process.hrtime?(e.exports=function(){return(t()-i)/1e6},n=process.hrtime,o=(t=function(){var e;return 1e9*(e=n())[0]+e[1]})(),u=1e9*process.uptime(),i=o-u):Date.now?(e.exports=function(){return Date.now()-r},r=Date.now()):(e.exports=function(){return(new Date).getTime()-r},r=(new Date).getTime())}).call(this)},function(e,t,n){"use strict";var r=n(11),o=[];(t=e.exports={}).callLater=function(e,t){var n=1e3*r();t&&(n+=t);for(var i={f:e,t:n},u=0;u<o.length;++u)if(o[u].t>n)return void o.splice(u,0,i);return o.push(i),i},t.cancelCall=function(e){var t=o.indexOf(e);t>=0&&o.splice(t,1)},t.nextEvent=function(){o.shift().f()},t.hasEvents=function(){return o.length>0},t.getEvents=function(){return o},t.resetEvents=function(){o.splice(0,o.length)},t.run=function(){for(;this.hasEvents();)this.nextEvent()},t.callImmediate=t.callLater,t.cancelImmediate=t.cancelCall},function(e,t,n){"use strict";var r=n(7),o=n(12),i=n(0),u=n(6),a=n(2).isProduction;(t=e.exports=function(){return new u(null,t.ActiveAsyncTool)}).ActiveAsyncTool=r,t.AsyncTool=r,t.AsyncToolTest=o,t.FutoInError=i,t.Errors=i,t.AsyncSteps=u,t.isProduction=a,t.installAsyncToolTest=function(e){t.ActiveAsyncTool=!1===e?r:o},t.assertAS=function(e){try{if(e.isAsyncSteps())return}catch(e){}throw new Error("Not an instance of AsyncSteps: "+e)}},function(e,t,n){"use strict";(t=e.exports=n(13)).ISync=n(1),t.Mutex=n(4),t.Throttle=n(3),t.Limiter=n(9),t.testcase=n(8)},function(e,t,n){"use strict";!function(t){var r=t.FutoIn||t.futoin||{};if(void 0===r.AsyncSteps){var o=n(14);t.$as=o,r.$as=o,t.FutoInError=o.FutoInError,r.AsyncSteps=o.AsyncSteps,t.FutoIn=r,t.futoin=r}e.exports=r.$as}(window)},function(e,t,n){"use strict";var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var i=n(15),u=Symbol("FutoIn Event Emitter"),a="_evt_",c="_evtonce_",s=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._max=n,this._scheduleCall=i.ActiveAsyncTool.callImmediate;var r=!0,o=!1,u=void 0;try{for(var s,l=t[Symbol.iterator]();!(r=(s=l.next()).done);r=!0){var f=s.value;this[""+a+f]=[],this[""+c+f]=[]}}catch(e){o=!0,u=e}finally{try{!r&&l.return&&l.return()}finally{if(o)throw u}}}return r(e,[{key:"on",value:function(e,t){try{var n=this[""+a+e];n.length===this._max&&console.warn("Hitting max handler limit for: "+e),n.push(t)}catch(t){throw new Error("Unknown event: "+e)}}},{key:"once",value:function(e,t){try{var n=this[""+c+e];n.length===this._max&&console.warn("Hitting max once handler limit for: "+e),n.push(t)}catch(t){throw new Error("Unknown event: "+e)}}},{key:"off",value:function(e,t){try{var n=""+a+e;this[n]=this[n].filter(function(e){return e!==t});var r=""+c+e;this[r]=this[r].filter(function(e){return e!==t})}catch(t){throw new Error("Unknown event: "+e)}}},{key:"emit",value:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];try{var i=function(e){t._scheduleCall(function(){return e.apply(void 0,r)})},u=!0,s=!1,l=void 0;try{for(var f,h=this[""+a+e][Symbol.iterator]();!(u=(f=h.next()).done);u=!0){i(f.value)}}catch(e){s=!0,l=e}finally{try{!u&&h.return&&h.return()}finally{if(s)throw l}}var _=this[""+c+e];if(_.length>0){var v=function(e){t._scheduleCall(function(){return e.apply(void 0,r)})},p=!0,y=!1,d=void 0;try{for(var m,b=_[Symbol.iterator]();!(p=(m=b.next()).done);p=!0){v(m.value)}}catch(e){y=!0,d=e}finally{try{!p&&b.return&&b.return()}finally{if(y)throw d}}this[""+c+e]=[]}}catch(t){throw new Error("Unknown event: "+e)}}}],[{key:Symbol.hasInstance,value:function(t){return void 0!==t[u]||t.constructor===e}},{key:"attach",value:function(t,n){var r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:8,s=t[u];if(void 0===s){var l=new e(n,i);Object.defineProperties(t,(o(r={},u,{configurable:!1,enumerable:!1,writable:!1,value:l}),o(r,"on",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return l.on(e,t)}}),o(r,"off",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return l.off(e,t)}}),o(r,"once",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return l.once(e,t)}}),o(r,"emit",{configurable:!1,enumerable:!1,writable:!1,value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return l.emit.apply(l,[e].concat(n))}}),r))}else{s._max=i;var f=!0,h=!1,_=void 0;try{for(var v,p=n[Symbol.iterator]();!(f=(v=p.next()).done);f=!0){var y=v.value;if(""+a+y in s)throw new Error('Event "'+y+'" has been already registered!');s[""+a+y]=[],s[""+c+y]=[]}}catch(e){h=!0,_=e}finally{try{!f&&p.return&&p.return()}finally{if(h)throw _}}}}},{key:"setMaxListeners",value:function(e,t){e[u]._max=t}},{key:"SYM_EVENT_EMITTER",get:function(){return u}}]),e}();e.exports=s},function(e,t,n){"use strict";var r=n(16),o=r.attach;o.EventEmitter=r,e.exports=o},function(e,t,n){"use strict";!function(t){var r=t.FutoIn||t.futoin||{};if(void 0===r.$asyncevent){var o=n(17);t.$asyncevent=o,r.$asyncevent=o,r.EventEmitter=o.EventEmitter,t.FutoIn=r,t.futoin=r}e.exports=r.$asyncevent}(window)}])}); |
@@ -28,3 +28,3 @@ 'use strict'; | ||
var scheduleCall = require('futoin-asyncsteps').AsyncTool.callImmediate; | ||
var $as = require('futoin-asyncsteps'); | ||
var SYM_EVENT_EMITTER = Symbol('FutoIn Event Emitter'); | ||
@@ -45,2 +45,3 @@ var ON_PREFIX = '_evt_'; | ||
this._max = max_listeners; | ||
this._scheduleCall = $as.ActiveAsyncTool.callImmediate; | ||
@@ -153,2 +154,4 @@ var _iteratorNormalCompletion = true; | ||
value: function emit(evt) { | ||
var _this = this; | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -161,3 +164,3 @@ args[_key - 1] = arguments[_key]; | ||
// let runtime deal with exceptions | ||
scheduleCall(function () { | ||
_this._scheduleCall(function () { | ||
return h.apply(undefined, args); | ||
@@ -200,3 +203,3 @@ }); | ||
// let runtime deal with exceptions | ||
scheduleCall(function () { | ||
_this._scheduleCall(function () { | ||
return h.apply(undefined, args); | ||
@@ -203,0 +206,0 @@ }); |
@@ -22,3 +22,3 @@ 'use strict'; | ||
const scheduleCall = require( 'futoin-asyncsteps' ).AsyncTool.callImmediate; | ||
const $as = require( 'futoin-asyncsteps' ); | ||
const SYM_EVENT_EMITTER = Symbol( 'FutoIn Event Emitter' ); | ||
@@ -36,2 +36,3 @@ const ON_PREFIX = '_evt_'; | ||
this._max = max_listeners; | ||
this._scheduleCall = $as.ActiveAsyncTool.callImmediate; | ||
@@ -110,3 +111,3 @@ for ( let evt of allowed_events ) { | ||
// let runtime deal with exceptions | ||
scheduleCall( () => h( ...args ) ); | ||
this._scheduleCall( () => h( ...args ) ); | ||
} | ||
@@ -120,3 +121,3 @@ | ||
// let runtime deal with exceptions | ||
scheduleCall( () => h( ...args ) ); | ||
this._scheduleCall( () => h( ...args ) ); | ||
} | ||
@@ -123,0 +124,0 @@ |
{ | ||
"name": "futoin-asyncevent", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "FutoIn AsyncEvent - FTN15 compliant event emitter", | ||
@@ -48,4 +48,4 @@ "main": "lib/asyncevent.js", | ||
"eslint": "^4.19.1", | ||
"futoin-asyncsteps": "^2.0.0", | ||
"grunt": "^1.0.2", | ||
"futoin-asyncsteps": "^2.1.1", | ||
"grunt": "^1.0.3", | ||
"grunt-babel": "^7.0.0", | ||
@@ -61,7 +61,7 @@ "grunt-contrib-connect": "^1.0.2", | ||
"mocha": "^5.2.0", | ||
"webpack": "^4.10.2" | ||
"webpack": "^4.12.0" | ||
}, | ||
"peerDependencies": { | ||
"futoin-asyncsteps": "^2.0.0" | ||
"futoin-asyncsteps": "^2.1.1" | ||
} | ||
} |
@@ -36,4 +36,5 @@ | ||
1. `setImmediate` / `setTimeout(handler, 0)` is used for each handler. | ||
1. ActiveAsyncTool from AsyncSteps is used for each handler. | ||
- All exceptions can be traced runtime-defined way. | ||
- Performance of setImmediate() with workaround for security-related slowdown in browsers. | ||
2. `EventEmitter` instance is hidden in `target[EventEmitter.SYM_EVENT_EMITTER]` property. | ||
@@ -40,0 +41,0 @@ - Almost no pollution to target object |
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
149763
978
405