export type RetryOptions = {
/**
* Function used to determine delay between retries
*/
backoff?: (attempt: number, maxRetries: number) => Promise<void>
} & (
| {
/**
* How many times the query will be retried (default: 5)
*/
maxRetries?: number
retryCondition?: undefined
}
| {
/**
* Callback to determine if a retry should be attempted.
* Return `true` for another retry and `false` to quit trying prematurely.
*/
retryCondition?: RetryConditionFunction
maxRetries?: undefined
}
)
1条答案
按热度按时间ltqd579y1#
你是对的,文档没有很好地展示这个功能,我不得不在仓库中寻找信息。
retry
函数有两个参数,第一个是基本查询函数,第二个是默认选项(RetryOptions
)配置对象。参见
RetryOptions
类型声明:字符串
该
backoff
属性是您感兴趣的型
它是一个接受attempt和max重试参数并返回Promise的函数。幸运的是,已经有一个默认的回退函数可以参考:
型
在我看来,这是一个非常好的默认函数,但如果需要的话,您可以构建自己的函数。
示例:
1秒、2秒、3秒、...maxRetries秒
型
每次重试1秒
型
在数组中查找。
型
按照文档中的示例来修饰基本查询函数。
型