mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-25 23:17:08 -04:00
23 lines
580 B
TypeScript
23 lines
580 B
TypeScript
import { readMsgpackFile } from '@pnpm/fs.msgpack-file'
|
|
|
|
export async function retryLoadMsgpackFile<T> (filePath: string): Promise<T> {
|
|
let retry = 0
|
|
/* eslint-disable no-await-in-loop */
|
|
while (true) {
|
|
await delay(500)
|
|
try {
|
|
return await readMsgpackFile<T>(filePath)
|
|
} catch (err: any) { // eslint-disable-line
|
|
if (retry > 2) throw err
|
|
retry++
|
|
}
|
|
}
|
|
/* eslint-enable no-await-in-loop */
|
|
}
|
|
|
|
export async function delay (time: number): Promise<void> {
|
|
return new Promise<void>((resolve) => setTimeout(() => {
|
|
resolve()
|
|
}, time))
|
|
}
|