The type of the resolved value / 解析值的类型
the function to retry / 重试的异步函数
the options for retry / 重试选项
Optionaldelay?: numberThe delay between retries, default is 0
重试间隔,默认为 0
Optionallimit?: numberThe total number of attempts (including the initial call), default is 3
总尝试次数(包含初始调用),默认 3
Optionalsignal?: AbortSignalAbortSignal for cancellation. When aborted, the retry will be rejected with AbortError.
用于取消的 AbortSignal。当触发中止时,重试将被拒绝并返回 AbortError。
Optionaltimeout?: numberMaximum total time in milliseconds for all retries. If exceeded, the retry will be rejected with TimeoutError.
所有重试的最大总时间(毫秒)。如果超过此时间,重试将被拒绝并返回 TimeoutError。
const result = await retry(async () => {
return await fetch('https://example.com').then((res) => res.json())
}, { limit: 3, delay: 1000 })
Retry a async function with a delay
重试异步函数并设置延迟