(fn: () => Promise<T>, options: { retryIntervalMilliseconds: number; maxRetries: number; output: Log })
| 39 | |
| 40 | // Generic retry function |
| 41 | export async function retry<T>(fn: () => Promise<T>, options: { retryIntervalMilliseconds: number; maxRetries: number; output: Log }): Promise<T> { |
| 42 | const { retryIntervalMilliseconds, maxRetries, output } = options; |
| 43 | let lastError: Error | undefined; |
| 44 | for (let i = 0; i < maxRetries; i++) { |
| 45 | try { |
| 46 | return await fn(); |
| 47 | } catch (err) { |
| 48 | lastError = err; |
| 49 | output.write( |
| 50 | `Retrying (Attempt ${i}) with error |
| 51 | '${toErrorText(String(err && (err.stack || err.message) || err))}'`, |
| 52 | LogLevel.Warning |
| 53 | ); |
| 54 | await new Promise(resolve => setTimeout(resolve, retryIntervalMilliseconds)); |
| 55 | } |
| 56 | } |
| 57 | throw lastError; |
| 58 | } |
| 59 | |
| 60 | export async function uriToWSLFsPath(uri: URI, cliHost: CLIHost): Promise<string> { |
| 61 | if (uri.scheme === 'file' && cliHost.type === 'wsl') { |
no test coverage detected