async-wait-until
Version:
Waits until the given predicate function returns a truthy value, then resolves
2 lines (1 loc) • 1.31 kB
JavaScript
function e(e,t,o,r){return new(o||(o=Promise))((function(n,i){function u(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(u,s)}c((r=r.apply(e,t||[])).next())}))}Object.defineProperty(exports,"__esModule",{value:!0}),"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=Number.POSITIVE_INFINITY,r=(r,n,i)=>{var u,s;const c=null!==(u="number"==typeof n?n:null==n?void 0:n.timeout)&&void 0!==u?u:5e3,l=null!==(s="number"==typeof n?i:null==n?void 0:n.intervalBetweenAttempts)&&void 0!==s?s:50;let p,a;return Promise.race([...c!==o?[new Promise(((e,o)=>{p=setTimeout((()=>{o(new t(c))}),c)}))]:[],new Promise(((t,o)=>{const n=()=>e(void 0,void 0,void 0,(function*(){try{const e=yield r();if(e)return void t(e);a=setTimeout(n,l)}catch(e){o(e)}}));n()}))]).finally((()=>{p&&clearTimeout(p),a&&clearTimeout(a)}))};exports.DEFAULT_INTERVAL_BETWEEN_ATTEMPTS_IN_MS=50,exports.DEFAULT_TIMEOUT_IN_MS=5e3,exports.TimeoutError=t,exports.WAIT_FOREVER=o,exports.default=r,exports.waitUntil=r;//# sourceMappingURL=commonjs.js.map
;