futoin-asyncevent
Advanced tools
Comparing version 1.1.1 to 2.0.0
=== 2.0.0 (2018-06-06) === | ||
CHANGED: to use futoin-asyncsteps event loop | ||
=== 1.1.1 (2018-06-06) === | ||
@@ -3,0 +6,0 @@ FIXED: crash Babel instanceof check issue |
@@ -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=2)}([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="undefined"!=typeof setImmediate&&setImmediate||function(e){return setTimeout(e,0)},a=Symbol("FutoIn Event Emitter"),u="_evt_",f="_evtonce_",l=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 a,l=t[Symbol.iterator]();!(r=(a=l.next()).done);r=!0){var c=a.value;this[""+u+c]=[],this[""+f+c]=[]}}catch(e){o=!0,i=e}finally{try{!r&&l.return&&l.return()}finally{if(o)throw i}}}return r(e,[{key:"on",value:function(e,t){try{var n=this[""+u+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[""+f+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=""+u+e;this[n]=this[n].filter(function(e){return e!==t});var r=""+f+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)})},a=!0,l=!1,c=void 0;try{for(var v,y=this[""+u+e][Symbol.iterator]();!(a=(v=y.next()).done);a=!0){o(v.value)}}catch(e){l=!0,c=e}finally{try{!a&&y.return&&y.return()}finally{if(l)throw c}}var s=this[""+f+e];if(s.length>0){var d=function(e){i(function(){return e.apply(void 0,n)})},h=!0,b=!1,m=void 0;try{for(var p,w=s[Symbol.iterator]();!(h=(p=w.next()).done);h=!0){d(p.value)}}catch(e){b=!0,m=e}finally{try{!h&&w.return&&w.return()}finally{if(b)throw m}}this[""+f+e]=[]}}catch(t){throw new Error("Unknown event: "+e)}}}],[{key:Symbol.hasInstance,value:function(t){return void 0!==t[a]||t.constructor===e}},{key:"attach",value:function(t,n){var r,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:8,l=t[a];if(void 0===l){var c=new e(n,i);Object.defineProperties(t,(o(r={},a,{configurable:!1,enumerable:!1,writable:!1,value:c}),o(r,"on",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return c.on(e,t)}}),o(r,"off",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return c.off(e,t)}}),o(r,"once",{configurable:!1,enumerable:!1,writable:!1,value:function(e,t){return c.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 c.emit.apply(c,[e].concat(n))}}),r))}else{l._max=i;var v=!0,y=!1,s=void 0;try{for(var d,h=n[Symbol.iterator]();!(v=(d=h.next()).done);v=!0){var b=d.value;if(""+u+b in l)throw new Error('Event "'+b+'" has been already registered!');l[""+u+b]=[],l[""+f+b]=[]}}catch(e){y=!0,s=e}finally{try{!v&&h.return&&h.return()}finally{if(y)throw s}}}}},{key:"setMaxListeners",value:function(e,t){e[a]._max=t}},{key:"SYM_EVENT_EMITTER",get:function(){return a}}]),e}();e.exports=l},function(e,t,n){"use strict";var r=n(0),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(1);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){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)}])}); |
@@ -28,5 +28,3 @@ 'use strict'; | ||
var scheduleCall = typeof setImmediate !== 'undefined' && setImmediate || function (c) { | ||
return setTimeout(c, 0); | ||
}; | ||
var scheduleCall = require('futoin-asyncsteps').AsyncTool.callImmediate; | ||
var SYM_EVENT_EMITTER = Symbol('FutoIn Event Emitter'); | ||
@@ -39,3 +37,3 @@ var ON_PREFIX = '_evt_'; | ||
* | ||
* @note Please avoid inheritting it, use EventEmitter.attach() instead! | ||
* @note Please avoid inheriting it, use EventEmitter.attach() instead! | ||
*/ | ||
@@ -42,0 +40,0 @@ |
@@ -22,6 +22,3 @@ 'use strict'; | ||
const scheduleCall = ( | ||
( ( typeof setImmediate !== 'undefined' ) && setImmediate ) || | ||
( ( c ) => setTimeout( c, 0 ) ) | ||
); | ||
const scheduleCall = require( 'futoin-asyncsteps' ).AsyncTool.callImmediate; | ||
const SYM_EVENT_EMITTER = Symbol( 'FutoIn Event Emitter' ); | ||
@@ -34,3 +31,3 @@ const ON_PREFIX = '_evt_'; | ||
* | ||
* @note Please avoid inheritting it, use EventEmitter.attach() instead! | ||
* @note Please avoid inheriting it, use EventEmitter.attach() instead! | ||
*/ | ||
@@ -37,0 +34,0 @@ class EventEmitter { |
{ | ||
"name": "futoin-asyncevent", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "FutoIn AsyncEvent - FTN15 compliant event emitter", | ||
@@ -48,2 +48,3 @@ "main": "lib/asyncevent.js", | ||
"eslint": "^4.19.1", | ||
"futoin-asyncsteps": "^2.0.0", | ||
"grunt": "^1.0.2", | ||
@@ -61,3 +62,6 @@ "grunt-babel": "^7.0.0", | ||
"webpack": "^4.10.2" | ||
}, | ||
"peerDependencies": { | ||
"futoin-asyncsteps": "^2.0.0" | ||
} | ||
} |
@@ -17,4 +17,6 @@ | ||
All other event emitters implementations are synchronous - they call handlers when event is emitted. | ||
As there is a known security-related timing problem of `setTimeout()` calls in browser, enhanced | ||
event loop is used from [futoin-asyncsteps](https://www.npmjs.com/package/futoin-asyncsteps) module. | ||
Second important feature - strict check of preconfigured allowed event types. | ||
Second important feature - strict check of allowed event types. | ||
@@ -188,3 +190,3 @@ **Documentation** --> [FutoIn Guide](https://futoin.org/docs/miscjs/asyncevent/) | ||
**Kind**: global class | ||
**Note**: Please avoid inheritting it, use EventEmitter.attach() instead! | ||
**Note**: Please avoid inheriting it, use EventEmitter.attach() instead! | ||
@@ -191,0 +193,0 @@ * [EventEmitter](#EventEmitter) |
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
148775
404
1
20
975