UNPKG

async-wait-until

Version:

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

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