diff --git a/source/exponential-backoff.ts b/source/exponential-backoff.ts index 59fe07e..89c3056 100644 --- a/source/exponential-backoff.ts +++ b/source/exponential-backoff.ts @@ -8,6 +8,51 @@ import { } from './errors.ts'; import { isWithinBounds } from './misc.ts'; +export type ExponentialBackoffOptions = { + + /** + * The maximum delay between attempts in milliseconds + */ + maxDelay: number; + + /** + * The maximum number of attempts. Passing 0 will result in infinite attempts. + */ + maxAttempts: number; + + /** + * The base delay between attempts in milliseconds + */ + baseDelay: number; + + /** + * The growth rate of the delay + */ + growthRate: number; + + /** + * The jitter of the delay as a percentage of growthRate. The jitter is subtracted from the delay. + */ + jitter: number; +}; + +/** + * The function to call to stop the retries. + * This mimics the AbortSignal.abort function by taking in a reason for stopping + * + * @param reason - The reason for stopping the retries. + */ +export type ExponentialBackoffStopRetriesFunction = (reason: unknown) => void; + +/** + * The parameters for the task function + * + * @param stopRetries - The function to call to stop the retries + */ +export type ExponentialBackoffCallbackParameters = { + stopRetries: ExponentialBackoffStopRetriesFunction; +}; + /** * Exponential backoff is a technique used to retry a function after a delay. * @@ -243,48 +288,3 @@ export class ExponentialBackoff { throw new ExponentialBackoffMaxRetriesHitError(errors); } } - -export type ExponentialBackoffOptions = { - - /** - * The maximum delay between attempts in milliseconds - */ - maxDelay: number; - - /** - * The maximum number of attempts. Passing 0 will result in infinite attempts. - */ - maxAttempts: number; - - /** - * The base delay between attempts in milliseconds - */ - baseDelay: number; - - /** - * The growth rate of the delay - */ - growthRate: number; - - /** - * The jitter of the delay as a percentage of growthRate. The jitter is subtracted from the delay. - */ - jitter: number; -}; - -/** - * The function to call to stop the retries. - * This mimics the AbortSignal.abort function by taking in a reason for stopping - * - * @param reason - The reason for stopping the retries. - */ -export type ExponentialBackoffStopRetriesFunction = (reason: unknown) => void; - -/** - * The parameters for the task function - * - * @param stopRetries - The function to call to stop the retries - */ -export type ExponentialBackoffCallbackParameters = { - stopRetries: ExponentialBackoffStopRetriesFunction; -};