We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promise.retry = function (promiseFn, times = 3) { return new Promise(async (resolve, reject) => { while (times--) { try { var ret = await promiseFn(); resolve(ret); break; } catch (error) { if (!times) reject(error); } } }); }; function getProm() { const n = Math.random(); return new Promise((resolve, reject) => { setTimeout(() => n > 0.9 ? resolve(n) : reject(n), 1000); }); } Promise.retry(getProm);
Originally posted by @bighamD in #387 (comment)
The text was updated successfully, but these errors were encountered:
因为 resolve(ret) 中的 ret 是一个 promise 对象,所以当前新建的 promise 对象的 resolve 方法是依赖这个 ret 的解决的,本身就有先后顺序,因此 async 和 await 直接去掉是不是也是可以的?
Sorry, something went wrong.
不影响
No branches or pull requests
Originally posted by @bighamD in #387 (comment)
The text was updated successfully, but these errors were encountered: