我想要一些 JavaScript 代码将 3 个东西作为参数:
我最终做的是使用for循环。我不想使用递归函数:这样,即使有 50 次尝试,调用堆栈也不会长 50 行。
这是代码的打字稿版本:
/**
* @async
* @function tryNTimes<T> Tries to resolve a {@link Promise<T>} N times, with a delay between each attempt.
* @param {Object} options Options for the attempts.
* @param {() => Promise<T>} options.toTry The {@link Promise<T>} to try to resolve.
* @param {number} [options.times=5] The maximum number of attempts (must be greater than 0).
* @param {number} [options.interval=1] The interval …Run Code Online (Sandbox Code Playgroud)