mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import type { BaseQueryEnhancer } from './baseQueryTypes';
|
|
interface StaggerOptions {
|
|
/**
|
|
* How many times the query will be retried (default: 5)
|
|
*/
|
|
maxRetries?: number;
|
|
/**
|
|
* Function used to determine delay between retries
|
|
*/
|
|
backoff?: (attempt: number, maxRetries: number) => Promise<void>;
|
|
}
|
|
declare function fail(e: any): never;
|
|
/**
|
|
* A utility that can wrap `baseQuery` in the API definition to provide retries with a basic exponential backoff.
|
|
*
|
|
* @example
|
|
*
|
|
* ```ts
|
|
* // codeblock-meta title="Retry every request 5 times by default"
|
|
* import { createApi, fetchBaseQuery, retry } from '@reduxjs/toolkit/query/react'
|
|
* interface Post {
|
|
* id: number
|
|
* name: string
|
|
* }
|
|
* type PostsResponse = Post[]
|
|
*
|
|
* // maxRetries: 5 is the default, and can be omitted. Shown for documentation purposes.
|
|
* const staggeredBaseQuery = retry(fetchBaseQuery({ baseUrl: '/' }), { maxRetries: 5 });
|
|
* export const api = createApi({
|
|
* baseQuery: staggeredBaseQuery,
|
|
* endpoints: (build) => ({
|
|
* getPosts: build.query<PostsResponse, void>({
|
|
* query: () => ({ url: 'posts' }),
|
|
* }),
|
|
* getPost: build.query<PostsResponse, string>({
|
|
* query: (id) => ({ url: `post/${id}` }),
|
|
* extraOptions: { maxRetries: 8 }, // You can override the retry behavior on each endpoint
|
|
* }),
|
|
* }),
|
|
* });
|
|
*
|
|
* export const { useGetPostsQuery, useGetPostQuery } = api;
|
|
* ```
|
|
*/
|
|
export declare const retry: BaseQueryEnhancer<unknown, StaggerOptions, void | StaggerOptions> & {
|
|
fail: typeof fail;
|
|
};
|
|
export {};
|