mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {timeout} from './timeout' 2 3export async function until( 4 retries: number, 5 delay: number, 6 cond: (v: any, err: any) => boolean, 7 fn: () => Promise<any>, 8): Promise<boolean> { 9 while (retries > 0) { 10 try { 11 const v = await fn() 12 if (cond(v, undefined)) { 13 return true 14 } 15 } catch (e: any) { 16 if (cond(undefined, e)) { 17 return true 18 } 19 } 20 await timeout(delay) 21 retries-- 22 } 23 return false 24}