Initial Commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type {
|
||||
LinearBackoffOptions,
|
||||
RetryStrategy,
|
||||
} from "../../types/retry.types.js";
|
||||
|
||||
/**
|
||||
* Creates a retry strategy with linearly increasing delay.
|
||||
*
|
||||
* `delay(attempt) = initial + (attempt - 1) * increment`, capped at `max`
|
||||
* if provided.
|
||||
*
|
||||
* @param opts - Linear backoff options.
|
||||
* @returns A `RetryStrategy` function.
|
||||
*/
|
||||
export function createLinearBackoff(opts: LinearBackoffOptions): RetryStrategy {
|
||||
const { initial, increment, max } = opts;
|
||||
return (attempt: number): number => {
|
||||
const delay = initial + (attempt - 1) * increment;
|
||||
return max !== undefined ? Math.min(delay, max) : delay;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user