UNPKG

foxts

Version:

Opinionated collection of common TypeScript utils by @SukkaW

1 lines 452 B
function t(o,e=50,n=null){if("object"==typeof e&&"aborted"in e&&(n=e,e=50),"number"==typeof e){const t=e;e=(o,e)=>{const n=setTimeout(o,t);e(()=>clearTimeout(n))}}n??=AbortSignal.timeout(5e3);const r=new Set,c=t=>r.add(t);return new Promise((t,i)=>{const a=async()=>{try{n.throwIfAborted();const i=await o();if(i)return void t(i);const f=e(a,c);"function"==typeof f&&r.add(f)}catch(t){i(t)}};a()}).finally(()=>{r.forEach(t=>t())})}export{t as waitFor};