@snap/camera-kit
Version:
Camera Kit Web
49 lines • 2.32 kB
TypeScript
import type { ChainableHandler, RequestMetadata } from "./HandlerChainBuilder";
/**
* Returns a cloned instance of Request if the input is of that type, otherwise returns the input unchanged.
*
* This is necessary when attempting to retry a request.
* It is not possible to reuse the same Request instance that has already been sent.
*/
export declare function ensureClonedRequest<T>(input: T): T;
export interface RetryingHandlerOptions<Req> {
/**
* Multiple used to increase the random backoff between attempts. Default is 3, usually doesn't need to be changed.
*/
backoffMultiple: number;
/**
* The minimum number of milliseconds to sleep between attempts.
*
* The actual number of milliseconds slept between attempts is chosen at random.
*/
baseSleep: number;
/**
* The maximum number of milliseconds to sleep between attempts. Note that this is not a timeout -- if multiple
* request attempts are made, the total request latency will be longer than this.
*
* The actual number of milliseconds slept between attempts is chosen at random.
*/
maxSleep: number;
/**
* The maximum number of retry attempts. The initial request is not counted against this number.
*/
maxRetries: number;
/**
* Determine if a given error is retryable. If `false` is returned, the error will be passed up to the Handler's
* caller and no additional retry attempts will be made.
*/
retryPredicate: (responseOrError: Req | Error, retryCount: number) => boolean;
}
/**
* Retry requests using an exponential backoff with jitter strategy.
*
* More about this approach to retries can be found
* [here](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/). This implementation uses the
* "Decorrelated jitter" algorithm described in that post. This offers a good tradeoff between call volume and latency,
* and also allows for convenient configurability.
*
* @param options
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
*/
export declare const createRetryingHandler: <Req, Res, Meta extends RequestMetadata>(options?: Partial<RetryingHandlerOptions<Res>>) => ChainableHandler<Req, Res, Req, Res, Meta>;
//# sourceMappingURL=retryingHandler.d.ts.map