@mudssky/jsutils
    Preparing search index...

    Function withRetry

    • 创建一个支持重试的函数包装器

      Type Parameters

      Parameters

      • fn: T

        需要重试的函数(支持同步和异步)

      • options: RetryOptions = {}

        重试配置

        • Optionaldelay?: number
        • OptionalmaxRetries?: number
        • OptionalshouldRetry?: (error: unknown) => boolean

      Returns (...args: Parameters<T>) => Promise<ReturnType<T>>

      包装后的函数

      // 基本用法
      const fetchWithRetry = withRetry(fetchData, { maxRetries: 3 });

      // 带延迟重试
      const fetchWithRetry = withRetry(fetchData, { maxRetries: 3, delay: 1000 });

      // 自定义重试条件
      const fetchWithRetry = withRetry(fetchData, {
      maxRetries: 3,
      shouldRetry: (error) => error.statusCode !== 404
      });