UNPKG

async-wait-until

Version:

Waits until the given predicate function returns a truthy value, then resolves

2 lines (1 loc) 1.23 kB
function e(e,t,o,n){return new(o||(o=Promise))((function(r,i){function u(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(u,c)}s((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class t extends Error{constructor(e){super(null!=e?`Timed out after waiting for ${e} ms`:"Timed out"),Object.setPrototypeOf(this,t.prototype)}}const o=50,n=5e3,r=Number.POSITIVE_INFINITY,i=(o,n,i)=>{var u,c;const s=null!==(u="number"==typeof n?n:null==n?void 0:n.timeout)&&void 0!==u?u:5e3,l=null!==(c="number"==typeof n?i:null==n?void 0:n.intervalBetweenAttempts)&&void 0!==c?c:50;let a,f;return Promise.race([...s!==r?[new Promise(((e,o)=>{a=setTimeout((()=>{o(new t(s))}),s)}))]:[],new Promise(((t,n)=>{const r=()=>e(void 0,void 0,void 0,(function*(){try{const e=yield o();if(e)return void t(e);f=setTimeout(r,l)}catch(e){n(e)}}));r()}))]).finally((()=>{a&&clearTimeout(a),f&&clearTimeout(f)}))};export{o as DEFAULT_INTERVAL_BETWEEN_ATTEMPTS_IN_MS,n as DEFAULT_TIMEOUT_IN_MS,t as TimeoutError,r as WAIT_FOREVER,i as default,i as waitUntil};//# sourceMappingURL=index.esm.js.map