How to retry a Promise resolution N times, with a delay between the attempts?
问题 I want some JavaScript code to take 3 things as parameters: A function returning a Promise. The maximum number of attempts. The delay between each attempt. What I ended up doing is using a for loop. I did not want to use a recursive function : this way, even if there are 50 attempts the call stack isn't 50 lines longer. Here is the typescript version of the code: /** * @async * @function tryNTimes<T> Tries to resolve a {@link Promise<T>} N times, with a delay between each attempt. * @param