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