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
tip 源码实现 实现promise.retry
Promise.retry = function (fn, num) { function executeFn() { return new Promise((resolve, reject) => { resolve(fn()) }).then(res => { return Promise.resolve(res) }).catch(e => { num--; if (num < 0) { return Promise.reject(e) } else { return executeFn() } }) } return executeFn() }; function getData() { let num = Math.floor((Math.random() * 10)); return new Promise((resolve, reject) => { if (num === 1) { resolve(num) } else { reject(num) } }) } Promise.retry(getData, 3).then(res => console.log(res)).catch(err => console.log('失败'));
浏览器缓存
The text was updated successfully, but these errors were encountered:
No branches or pull requests
tip
源码实现
实现promise.retry
浏览器缓存
The text was updated successfully, but these errors were encountered: