UNPKG

async-wait-until

Version:

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

2 lines (1 loc) 1.31 kB
var asyncWaitUntil=function(e){"use strict";function t(e,t,n,o){return new(n||(n=Promise))((function(r,i){function u(e){try{s(o.next(e))}catch(e){i(e)}}function c(e){try{s(o.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,c)}s((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class n extends Error{constructor(e){super(null!=e?`Timed out after waiting for ${e} ms`:"Timed out"),Object.setPrototypeOf(this,n.prototype)}}const o=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 a,f;return Promise.race([...s!==o?[new Promise(((e,t)=>{a=setTimeout((()=>{t(new n(s))}),s)}))]:[],new Promise(((n,o)=>{const r=()=>t(void 0,void 0,void 0,(function*(){try{const t=yield e();if(t)return void n(t);f=setTimeout(r,l)}catch(e){o(e)}}));r()}))]).finally((()=>{a&&clearTimeout(a),f&&clearTimeout(f)}))};return e.DEFAULT_INTERVAL_BETWEEN_ATTEMPTS_IN_MS=50,e.DEFAULT_TIMEOUT_IN_MS=5e3,e.TimeoutError=n,e.WAIT_FOREVER=o,e.default=r,e.waitUntil=r,Object.defineProperty(e,"__esModule",{value:!0}),e}({});//# sourceMappingURL=iife.js.map