UNPKG

futoin-asyncsteps

Version:

Mimic traditional threads in single threaded event loop

1 lines 31.7 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["futoin-asyncsteps"]=e():t.$as=e()}(self,(()=>{return t={502:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,u(r.key),r)}}function u(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}var c=n(839),a=n(558).InternalError,s=n(5),l=n(12),f=n(464),h=f.isProduction,_=f.checkFunc,y=f.checkOnError,p=f.noop,v=f.loop,m=f.repeat,b=f.forEach,d=f.as_await,w=f.EMPTY_ARRAY,g=f.newExecStack,x=h?p:function(t){t._stack.length>0&&t.error(a,"Top level add in execution")},k=h?p:function(t,e,n){x(t),_(t,e),y(t,n)},S=100,E=null,j=function(t){t._post_exec=p,t._execute()},O=function(){function t(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),null===n&&(n=function(){return this.state}),this.state=n,this._queue=[],this._stack=[],this._exec_stack=g(),this._in_exec=!1,this._post_exec=p,this._exec_event=null,this._next_args=w,this._async_tool=r;var o=r.callImmediate,i=function(){S=100,E=e,e._exec_event=null,e._execute()};this._scheduleExecute=function(){--S<=0||!e._in_exec||E!==e?e._exec_event=o(i):e._in_exec&&(e._post_exec=j)}}return e=t,n=[{key:"add",value:function(t,e){return k(this,t,e),this._queue.push([t,e]),this}},{key:"parallel",value:function(t){x(this),y(this,t);var e=new l(this,this);return this._queue.push([function(t){e.executeParallel(t)},t]),e}},{key:"sync",value:function(t,e,n){return k(this,e,n),t.sync(this,e,n),this}},{key:"error",value:function(t,e){this.state.error_info=e;var n=new Error(t);throw this._in_exec||(this.state.last_exception=n,this._handle_error(t)),n}},{key:"copyFrom",value:function(t){this._queue.push.apply(this._queue,t._queue);var e=t.state,n=this.state;for(var r in e)r in n||(n[r]=e[r]);return this}},{key:"_handle_success",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:w,e=this._stack;e.length||this.error(a,"Invalid success completion"),this._next_args=t;for(var n=e[e.length-1];;){var r=n._limit_event;if(r&&(this._async_tool.cancelCall(r),n._limit_event=null),n._cleanup(),e.pop(),!e.length)break;if((n=e[e.length-1])._queue.length)break}(e.length||this._queue.length)&&this._scheduleExecute()}},{key:"_handle_error",value:function(t){if(this._exec_event)this.cancel();else{this._next_args=w;var e=this._stack,n=this._exec_stack;this.state.async_stack=n;for(var r=this._in_exec,o=!0;e.length;){var i=e[e.length-1],u=i._limit_event,c=i._on_cancel,a=i._on_error;if(u&&(this._async_tool.cancelCall(u),i._limit_event=null),c&&(c.call(null,i),i._on_cancel=null),a){var s=e.length;i._queue=null,i._on_error=null,n.push(a);try{if(this._in_exec=!0,a.call(null,i,t),s!==e.length){o=!1;break}if(null!==i._queue){o=!1,this._scheduleExecute();break}}catch(e){this.state.last_exception=e,t=e.message}finally{this._in_exec=r}}i._cleanup(),e.pop()}o?this._queue=[]:r||this._post_exec(this)}}},{key:"cancel",value:function(){this._next_args=w;var t=this._exec_event;t&&(this._async_tool.cancelImmediate(t),this._exec_event=null);for(var e=this._stack,n=this._async_tool;e.length;){var r=e.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 t=E;return E=this,this._execute(),E=t,this}},{key:"_execute",value:function(){var t,e=this._stack;if((t=e.length?e[e.length-1]._queue:this._queue).length){var n=t.shift(),r=n[0];this._exec_stack.push(r);var i=this._next_args,u=i.length,c=new s(this,n[1],i);e.push(c);try{var a=e.length;this._in_exec=!0,u?(this._next_args=w,r.apply(void 0,[c].concat(function(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return o(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(i)))):r(c),a===e.length&&(null!==c._queue?this._scheduleExecute():c._on_cancel||c._limit_event||this._handle_success(this._next_args))}catch(t){this.state.last_exception=t,this._handle_error(t.message)}finally{this._in_exec=!1}this._post_exec(this)}}},{key:"_burst_success",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:w;try{this._in_exec=!0,E=this,this._handle_success(t)}catch(t){this.state.last_exception=t,this._handle_error(t.message)}finally{this._in_exec=!1}this._post_exec(this)}},{key:"loop",value:function(t,e){return k(this,t),v(this,this,t,e),this}},{key:"repeat",value:function(t,e,n){return k(this,e),m(this,this,t,e,n),this}},{key:"forEach",value:function(t,e,n){return k(this,e),b(this,this,t,e,n),this}},{key:"successStep",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];x(this);var o=this._queue;return o.length>0?o.push([function(){t._handle_success(n)},void 0]):this._next_args=n,this}},{key:"await",value:function(t,e){return x(this),d(this,this,t,e),this}},{key:"promise",value:function(){var t=this;return x(this),new Promise((function(e,n){var r=t._queue;t._queue=[[function(t){t._queue=r},function(t,e){n(new Error(e))}],[function(t,n){e(n)},void 0]],E=t,t._execute()}))}},{key:"newInstance",value:function(){return new t(null,this._async_tool)}},{key:"isAsyncSteps",value:function(){return!0}}],n&&i(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();t.exports=O},558:t=>{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,o(r.key),r)}}function r(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t){var n=function(t){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=e(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==e(n)?n:n+""}var i=r((function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}));["ConnectError","CommError","UnknownInterface","NotSupportedVersion","NotImplemented","Unauthorized","InternalError","InvokerError","InvalidRequest","DefenseRejected","PleaseReauth","SecurityError","Timeout","LoopBreak","LoopCont"].forEach((function(t){return Object.defineProperty(i,t,{enumerable:!0,value:t})})),t.exports=i},73:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,i(r.key),r)}}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}var u=n(558).NotImplemented,c=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)},(e=[{key:"sync",value:function(t,e,n){t.error(u,"#sync() API")}}])&&o(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();t.exports=c},845:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,i(r.key),r)}}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}var s=n(73),l=n(682),f=n(449),h=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=c(e),function(t,e){if(e&&("object"==r(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,u()?Reflect.construct(e,n||[],c(t).constructor):e.apply(t,n))}(this,e))._mutex=new l(n.concurrent||1,n.max_queue||0),t._throttle=new f(n.rate||1,n.period_ms||1e3,n.burst||0),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}(e,t),n=e,(i=[{key:"sync",value:function(t,e,n){var r=this;t.sync(this._mutex,(function(t){t._root._next_args=t._call_args,t.sync(r._throttle,e,n)}))}}])&&o(n.prototype,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i}(s);t.exports=h},682:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,i(r.key),r)}}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}var s=n(73),l=n(558).DefenseRejected,f=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=c(e),function(t,e){if(e&&("object"==r(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,u()?Reflect.construct(e,n||[],c(t).constructor):e.apply(t,n))}(this,e))._max=n,t._locked=0,t._owners=new WeakMap,t._queue=[],t._max_queue=o,t._release_handler=function(e){t._release(e._root)},t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}(e,t),n=e,(i=[{key:"_lock",value:function(t,e){var n=this._owners,r=n.get(e);if(r)return n.set(e,r+1),!0;if(this._locked>=this._max){var o=this._queue,i=this._max_queue;return null!==i&&o.length>=i&&e.error(l,"Mutex queue limit"),o.push(t),!1}return this._locked+=1,n.set(e,1),!0}},{key:"_release",value:function(t){var e=this._owners,n=e.get(t);if(n){if(n>1)return void e.set(t,n-1);e.delete(t),this._locked-=1;for(var r=this._queue;r.length;){var o=r.shift();if(o.state){var i=o._root;this._lock(o,i),i._handle_success(o._call_args);break}}}else{var u=this._queue.indexOf(t);u>=0&&this._queue.splice(u,1)}}},{key:"sync",value:function(t,e,n){var r=this;t.add((function(t){!function(t,e,n,r){var o=t._root;t._on_cancel=e._release_handler,t._queue=[[function(n){e._lock(t,o)?o._handle_success(t._call_args):(n.waitExternal(),n._call_args=t._call_args)},void 0],[n,r],[function(t){e._release(o),o._handle_success(t._call_args)},void 0]]}(t,r,e,n)}))}}])&&o(n.prototype,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i}(s);t.exports=f},449:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,i(r.key),r)}}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(u=function(){return!!t})()}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}var l=n(73),f=n(558).DefenseRejected,h=n(464).prev_queue,_=function(t){function e(t){var n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=c(e),function(t,e){if(e&&("object"==r(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,u()?Reflect.construct(e,n||[],c(t).constructor):e.apply(t,n))}(this,e))._max=t,n._current=0;var a=n._queue=[];return n._timer=null,n._period_ms=o,n._max_queue=i,n._cancel_handler=function(t){var e=a.indexOf(t);e>=0&&a.splice(e,1)},n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&a(t,e)}(e,t),n=e,(i=[{key:"_lock",value:function(t){if(this._ensureTimer(),this._current>=this._max){var e=this._queue,n=this._max_queue;return null!==n&&e.length>=n&&t.error(f,"Throttle queue limit"),e.push(t),!1}return this._current+=1,!0}},{key:"_ensureTimer",value:function(){var t=this;this._timer||(this._timer=setInterval((function(){t._resetPeriod()}),this._period_ms))}},{key:"_resetPeriod",value:function(){this._current=0;var t=this._queue;if(!t.length)return clearInterval(this._timer),void(this._timer=null);for(var e=this._max,n=0;t.length&&n<e;){var r=t.shift();if(r.state){++n;var o=r._root;o._handle_success(o._next_args)}}this._current=n}},{key:"sync",value:function(t,e,n){var r=this;t.add((function(t){!function(t,e,n,r){var o=t._root;e._lock(t)?(t._on_error=r,n.apply(void 0,[t].concat(function(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return s(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}(t._call_args)))):(t._on_cancel=e._cancel_handler,o._next_args=t._call_args,h(o).unshift([n,r]))}(t,r,e,n)}))}}])&&o(n.prototype,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i}(l);t.exports=_},5:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,i(r.key),r)}}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}var u=n(12),c=n(558),a=c.InternalError,s=c.Timeout,l=c.LoopBreak,f=c.LoopCont,h=n(464),_=h.isProduction,y=h.checkFunc,p=h.checkOnError,v=h.noop,m=h.loop,b=h.repeat,d=h.forEach,w=h.LOOP_TERM_LABEL,g=h.as_await,x=_?v:function(t){var e=t._root;if(e){var n=e._stack;if(n){if(n[n.length-1]===t)return;e.error(a,"Invalid call (sanity check)")}}throw new Error("InternalError: Unexpected call, object is out of service")},k=_?v:function(t,e,n){x(t),y(t,e),p(t,n)},S=function(){return t=function t(e,n,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._root=e,this.state=e.state,this._queue=null,this._call_args=r,this._on_error=n,this._on_cancel=null,this._limit_event=null},e=[{key:"add",value:function(t,e){k(this,t,e);var n=[t,e],r=this._queue;return r?r.push(n):this._queue=[n],this}},{key:"parallel",value:function(t){var e=new u(this._root,this);return this.add((function(t){e.executeParallel(t)}),t),e}},{key:"success",value:function(){x(this),null!==this._queue&&this.error(a,"Invalid success() call");for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];this._root._handle_success(e)}},{key:"error",value:function(t,e){x(this),this._root.error(t,e)}},{key:"setTimeout",value:function(t){var e=this;x(this);var n=this._root._async_tool;return null!==this._limit_event&&n.cancelCall(this._limit_event),this._limit_event=n.callLater((function(){!function(t){t._limit_event=null;var e=t.state;e.error_info=void 0,e.last_exception=new Error(s),t._root._handle_error(s)}(e)}),t),this}},{key:"setCancel",value:function(t){return this._on_cancel=t,this}},{key:"waitExternal",value:function(){return this._on_cancel=v,this}},{key:"copyFrom",value:function(t){if(x(this),t._queue.length){var e=this._queue;null===e&&(e=[],this._queue=e),e.push.apply(e,t._queue)}var n=t.state,r=this.state;for(var o in n)void 0===r[o]&&(r[o]=n[o]);return this}},{key:"loop",value:function(t,e){return k(this,t),m(this,this._root,t,e),this}},{key:"repeat",value:function(t,e,n){return k(this,e),b(this,this._root,t,e,n),this}},{key:"forEach",value:function(t,e,n){return k(this,e),d(this,this._root,t,e,n),this}},{key:"break",value:function(t){x(this),this.state[w]=t,this._root.error(l)}},{key:"continue",value:function(t){x(this),this.state[w]=t,this._root.error(f)}},{key:"successStep",value:function(){for(var t=this,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];x(this);var o=this._queue;return o&&o.length?o.push([function(){t._root._handle_success(n)},void 0]):this._root._next_args=n,this}},{key:"await",value:function(t,e){return x(this),g(this,this._root,t,e),this}},{key:"sync",value:function(t,e,n){return k(this,e,n),t.sync(this,e,n),this}},{key:"newInstance",value:function(){return this._root.newInstance()}},{key:"isAsyncSteps",value:function(){return!0}},{key:"_cleanup",value:function(){this._root=null,this.state=null}}],e&&o(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();t.exports=S},839:(t,e)=>{"use strict";if(e=t.exports={},"undefined"==typeof setImmediate){e.callLater=function(t,e){return setTimeout(t,e)},e.cancelCall=function(t){return clearTimeout(t)},window._FutoInEventLoopQueue=window._FutoInEventLoopQueue||[];var n=window._FutoInEventLoopQueue,r=window.performance,o=null,i=function(){o&&clearTimeout(o),o=setTimeout(u,0)},u=function(){o=null;for(var t=r.now()+10;n.length;){var e=n.shift();try{e()}catch(t){throw i(),t}if(r.now()>=t){i();break}}};e.callImmediate=function(t){n.length||i();var e=function(){t()};return n.push(e),e},e.cancelImmediate=function(t){var e=n.indexOf(t);e>=0&&n.splice(e,1)}}else e.callLater=function(t,e){return setTimeout(t,e)},e.cancelCall=function(t){clearTimeout(t)},e.callImmediate=function(t){return setImmediate(t)},e.cancelImmediate=function(t){clearImmediate(t)}},451:(t,e,n)=>{"use strict";var r=n(491),o=[];(e=t.exports={}).callLater=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=1e3*r();e&&(n+=e);for(var i={f:t,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},e.cancelCall=function(t){var e=o.indexOf(t);e>=0&&o.splice(e,1)},e.nextEvent=function(){o.shift().f()},e.hasEvents=function(){return o.length>0},e.getEvents=function(){return o},e.resetEvents=function(){o.splice(0,o.length)},e.run=function(){for(;this.hasEvents();)this.nextEvent()},e.callImmediate=e.callLater,e.cancelImmediate=e.cancelCall},12:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,i(r.key),r)}}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}var u=n(464),c=u.checkFunc,a=u.checkOnError,s=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._root=e,this._as=n,this._queue=[],this._psteps=[],this._complete_count=0}return e=t,(n=[{key:"add",value:function(t,e){return c(this,t),a(this,e),this._queue.push([t,e]),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(t,e){try{this._as.error(t,e)}catch(t){}}},{key:"executeParallel",value:function(e){var n=this,r=this._queue,o=this._root;if(o!==e._root){var i=new t(e._root,e);return i._queue.push.apply(i._queue,r),void i.executeParallel(e)}if(this._as=e,r.length){e._on_cancel=function(){n.cancel()};var u=this._psteps,c=function(t){n._complete()},a=function(t,e){n._error(e,t.state.error_info)},s=o.constructor;r.forEach((function(t){var n=new s(e.state,o._async_tool);n._queue.push([function(e){e._queue=[[t[0],t[1]]]},a],[c,void 0]),u.push(n)})),u.forEach((function(t){t.execute()}))}else this._complete()}},{key:"cancel",value:function(){this._psteps.forEach((function(t){t.cancel()})),this._cleanup()}},{key:"isAsyncSteps",value:function(){return!0}},{key:"_cleanup",value:function(){this._root=null,this._as=null,this._psteps=null}}])&&o(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();t.exports=s},953:(t,e,n)=>{"use strict";!function(e){var r=e.FutoIn||e.futoin||{};if(void 0===r.AsyncSteps){var o=n(368);e.$as=o,r.$as=o,e.FutoInError=o.FutoInError,r.AsyncSteps=o.AsyncSteps,e.FutoIn=r,e.futoin=r}t.exports=r.$as}(window)},464:(t,e,n)=>{"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,i(r.key),r)}}function i(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}var c=n(558),a=(c.InternalError,c.LoopCont),s=c.LoopBreak,l="undefined"==typeof Symbol?function(t){return t}:function(t){return Symbol(t)},f=l("_loop_term_label"),h=function(t,e,n,r,o){o&&o()||t.add((function(t){var i=t.state,u=e._exec_stack,c=u.length,l=[n,function(e,n){!function(t,e,n,r,o){if(e===a){var i=r[f];i&&i!==o||(r.last_exception=null,t._root._handle_success())}else if(e===s){var u=r[f];u&&u!==o||(r.last_exception=null,n._queue.length=0,t._root._handle_success())}}(e,n,t,i,r)}],h=[function(t){o&&o()||(u.length=c,_())},null],_=function(){t._queue=[l,h]};_()}))},_=function(t,e,n,r,o){var i=0,u=n;h(t,e,(function(t){r(t,i++)}),o,(function(){return i>=u}))},y=[];Object.freeze(y);var p=function(){};t.exports=e={noop:p,makeSym:l,loop:h,repeat:_,forEach:function(t,e,n,r,o){if(Array.isArray(n)){var i=n;_(t,e,i.length,(function(t,e){r(t,e,i[e])}),o)}else if("undefined"!=typeof Map&&n instanceof Map){var c=n.entries();h(t,e,(function(t){var e=c.next();e.done&&t.break();var n,o,i=(n=e.value,o=2,function(t){if(Array.isArray(t))return t}(n)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,o,i,u,c=[],a=!0,s=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;a=!1}else for(;!(a=(r=i.call(n)).done)&&(c.push(r.value),c.length!==e);a=!0);}catch(t){s=!0,o=t}finally{try{if(!a&&null!=n.return&&(u=n.return(),Object(u)!==u))return}finally{if(s)throw o}}return c}}(n,o)||function(t,e){if(t){if("string"==typeof t)return u(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}(n,o)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),a=i[0],s=i[1];r(t,a,s)}),o)}else{var a=n,s=Object.keys(a);_(t,e,s.length,(function(t,e){r(t,s[e],a[s[e]])}),o)}},LOOP_TERM_LABEL:f,as_await:function(t,e,n,r){var o,i;n.then((function(t){o?o.state&&e._burst_success([t]):i=function(){e._handle_success([t])}}),(function(t){o?function(t,e,n){var r=t.state;if(r){var o="PromiseReject";if(t._on_cancel=null,n instanceof Error)r.last_exception=n,r.error_info=void 0,e._handle_error(o);else{var i=n||o;r.last_exception=new Error(i),r.error_info=void 0,e._handle_error(i)}}}(o,e,t):(o=null,i=t instanceof Error?function(){throw t}:function(e){e.error(t||"PromiseReject")})})),t.add((function(t){i?i(t):(o=t,t._on_cancel=function(){if(o){o=null;try{n.cancel()}catch(t){}}})}),r)},EMPTY_ARRAY:y,prev_queue:function(t){var e=t._stack,n=e.length;return n>1?e[n-2]._queue:t._queue}},e.isProduction=!0,e.checkFunc=p,e.checkOnError=p;var v=new(function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)},(e=[{key:"push",value:function(){}},{key:"length",get:function(){return 0},set:function(t){}}])&&o(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}());Object.freeze(v),e.newExecStack=function(){return v}},368:(t,e,n)=>{"use strict";(e=t.exports=n(360)).ISync=n(73),e.Mutex=n(682),e.Throttle=n(449),e.Limiter=n(845),e.testcase=n(257)},360:(t,e,n)=>{"use strict";var r=n(839),o=n(451),i=n(558),u=n(502),c=n(464).isProduction;(e=t.exports=function(){return new u(null,e.ActiveAsyncTool)}).ActiveAsyncTool=r,e.AsyncTool=r,e.AsyncToolTest=o,e.FutoInError=i,e.Errors=i,e.AsyncSteps=u,e.isProduction=c,e.installAsyncToolTest=function(t){e.ActiveAsyncTool=!1===t?r:o},e.assertAS=function(t){try{if(t.isAsyncSteps())return}catch(t){}throw new Error("Not an instance of AsyncSteps: ".concat(t))}},257:(t,e,n)=>{"use strict";var r=n(502);t.exports=function(t,e){return function(n){var o=this,i=new r;i.add((function(n){n.add((function(n){t.call(o,n),e&&n.add((function(t){t.error("NegativeTestMustThrow")}))}),e)}),(function(t,e){console.log("ERROR: ".concat(e," (").concat(t.state.error_info,")")),n(t.state.last_exception||new Error("Generic Fail"))})),i.add((function(t){return n()})),i.execute()}}},491:function(t){(function(){var e,n,r,o,i,u;"undefined"!=typeof performance&&null!==performance&&performance.now?t.exports=function(){return performance.now()}:"undefined"!=typeof process&&null!==process&&process.hrtime?(t.exports=function(){return(e()-i)/1e6},n=process.hrtime,o=(e=function(){var t;return 1e9*(t=n())[0]+t[1]})(),u=1e9*process.uptime(),i=o-u):Date.now?(t.exports=function(){return Date.now()-r},r=Date.now()):(t.exports=function(){return(new Date).getTime()-r},r=(new Date).getTime())}).call(this)}},e={},function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}(953);var t,e}));