UNPKG

sequelize-adapter

Version:

Use Unit Of Wrok pattern to wrap sequelize up.

28 lines (25 loc) 548 B
const sleep = ( ms: number ) => new Promise<void>((resolve) => { setTimeout(() => { resolve(); }, ms); }); export const retryFunc = async ( count: number, waitingMillisecond: number, func: (currentCount: number) => boolean | Promise<boolean>, currentCount = 1 ) => { const residue = count - currentCount; if (residue < 0) { return; } const bo = await func(currentCount); if (bo) { return; } await sleep(waitingMillisecond); await retryFunc(count, waitingMillisecond, func, currentCount + 1); }