Skip to content

Commit

Permalink
fix: export RetryOptions interface
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Sep 15, 2023
1 parent 82dfb1c commit 6870232
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/shared-lib/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export async function ignoreEnoentAsync<T>(fn: () => Promise<T>): Promise<T | un
}
}

export interface RetryOptions {
beforeRetry: ((error: unknown) => Promise<void>) | undefined;
handleError: ((error: unknown) => Promise<void>) | undefined;
retryCount: number;
retryLogger: ((message: string) => void) | undefined;
sleepMilliseconds: number;
}

/**
* Retry the given function.
* @param func The function to retry.
Expand All @@ -64,12 +72,12 @@ export async function ignoreEnoentAsync<T>(fn: () => Promise<T>): Promise<T | un
export async function withRetry<T>(
func: (failedCount: number) => Promise<T>,
{
beforeRetry = undefined as ((error: unknown) => Promise<void>) | undefined,
handleError = undefined as ((error: unknown) => Promise<void>) | undefined,
beforeRetry = undefined,
handleError = undefined,
retryCount = 3,
retryLogger = undefined as ((message: string) => void) | undefined,
retryLogger = undefined,
sleepMilliseconds = 0,
}
}: RetryOptions
): Promise<T> {
let failedCount = 0;
for (;;) {
Expand Down

0 comments on commit 6870232

Please sign in to comment.