UNPKG

async-wait-until

Version:

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

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