@apigames/async-interval
Version:
Modern version of setInterval for promises and async functions available in Node.js and browsers.
2 lines • 2.61 kB
JavaScript
/*! For license information please see set-interval-async.iife.js.LICENSE.txt */
var SetIntervalAsync;(()=>{"use strict";var e={143(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.SetIntervalAsyncTimer=void 0;class n{#e=void 0;#t=void 0;#n=!1;static startTimer(e,t,r,...s){r=Math.min(Math.max(Math.trunc(r),10),2147483647);const i=new n;return i.#r(e,t,r,r,...s),i}static async stopTimer(e){e.#n=!0,e.#e&&clearTimeout(e.#e),e.#t&&await e.#t}#r(e,t,n,r,...s){this.#e=setTimeout(async()=>{this.#e=void 0,this.#t=this.#s(e,t,n,...s),await this.#t,this.#t=void 0},r)}async#s(e,t,n,...r){const s=(new Date).getTime();try{await t(...r)}finally{if(!this.#n){const i=(new Date).getTime()-s,a="dynamic"===e?n>i?n-i:0:n;this.#r(e,t,n,a,...r)}}}}t.SetIntervalAsyncTimer=n},273(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.clearIntervalAsync=void 0,t.setIntervalAsync=function(e,t,...n){if("function"!=typeof e)throw new TypeError("First argument is not a function");if("number"!=typeof t)throw new TypeError("Second argument is not a number");return s.SetIntervalAsyncTimer.startTimer("dynamic",e,t,...n)};const r=n(574);Object.defineProperty(t,"clearIntervalAsync",{enumerable:!0,get:function(){return r.clearIntervalAsync}});const s=n(143)},274(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.clearIntervalAsync=void 0,t.setIntervalAsync=function(e,t,...n){if("function"!=typeof e)throw new TypeError("First argument is not a function");if("number"!=typeof t)throw new TypeError("Second argument is not a number");return s.SetIntervalAsyncTimer.startTimer("fixed",e,t,...n)};const r=n(574);Object.defineProperty(t,"clearIntervalAsync",{enumerable:!0,get:function(){return r.clearIntervalAsync}});const s=n(143)},574(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.clearIntervalAsync=async function(e){if(!(e instanceof r.SetIntervalAsyncTimer))throw new TypeError("First argument is not an instance of SetIntervalAsyncTimer");await r.SetIntervalAsyncTimer.stopTimer(e)};const r=n(143)}},t={};function n(r){var s=t[r];if(void 0!==s)return s.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}var r={};(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.fixed=e.dynamic=e.clearIntervalAsync=e.setIntervalAsync=void 0;const t=n(574);Object.defineProperty(e,"clearIntervalAsync",{enumerable:!0,get:function(){return t.clearIntervalAsync}});const s=n(273),i=n(274),a=s.setIntervalAsync;e.setIntervalAsync=a;const o={setIntervalAsync:s.setIntervalAsync};e.dynamic=o;const c={setIntervalAsync:i.setIntervalAsync};e.fixed=c})(),SetIntervalAsync=r})();