Created
July 6, 2020 07:58
-
-
Save mactanxin/047e521ec1c945dd8c17e4c07bde738e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let retry = function(fn, maxTime) { | |
let counter = 0; | |
function execFunc () { | |
return new Promise((resolve, reject) => { | |
console.log(`第${counter}次请求`); | |
resolve(fn); | |
}).then(res => { | |
return Promise.resolve(res); | |
}).catch(e=>{ | |
counter += 1; | |
if(counter >= maxTime) { | |
return Promise.reject(e) | |
} else { | |
return execFunc() | |
} | |
}) | |
} | |
return execFunc() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment