@meld-ts/core
    Preparing search index...

    Function retryFn

    • 创建感知重试状态的函数

      fn 的第一个参数为 RetryFnParams,包含 attempt 和 options, 允许根据重试次数做差异化处理。返回的函数剥掉 RetryFnParams, 只暴露业务参数。

      Type Parameters

      • T
      • Args extends unknown[]

      Parameters

      Returns (...args: Args) => Promise<Awaited<T>>

      只保留业务参数的包装函数

      const fetchWithFallback = retryFn(
      ({ attempt }, id: string) => {
      const url = attempt === 1 ? '/api/primary' : '/api/fallback';
      return fetch(`${url}/${id}`).then(r => r.json());
      },
      { attempts: 3 },
      );

      const data = await fetchWithFallback('123');