UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

42 lines (41 loc) 1.38 kB
/** * @module Resilience */ import { type AsyncMiddlewareFn, type HookContext } from "../../../hooks/_module.js"; import { type RetrySettings } from "../../../resilience/middlewares/retry/retry.types.js"; /** * The `retry` middleware enables automatic retries for all errors or specific errors, with configurable backoff policies. * An error will be thrown when all retry attempts fail. * * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares * * @example * ```ts * import { retry } from "@daiso-tech/core/resilience"; * import { AsyncHooks } from "@daiso-tech/core/hooks"; * import { TimeSpan } from "@daiso-tech/core/time-span"; * * const data = await new AsyncHooks( * async (url: string, signal?: AbortSignal): Promise<unknown> => { * const response = await fetch(url, { signal }); * const json = await response.json(); * if (!response.ok) { * return json; * } * return json; * }, * [retry()], * { * signalBinder: { * getSignal: (args) => args[1], * forwardSignal: (args, signal) => { * args[1] = signal; * } * } * } * ) * .invoke("URL"); * ``` */ export declare function retry<TParameters extends unknown[], TReturn, TContext extends HookContext>(settings?: NoInfer<RetrySettings<TParameters, TContext>>): AsyncMiddlewareFn<TParameters, TReturn, TContext>;