Created
April 28, 2016 14:41
-
-
Save Nautigsam/f03e03f70754380bf940c4daa6362d1d to your computer and use it in GitHub Desktop.
Show the use of loopCall, which call a function (here failedFunc) and return a promise immadiately or after maxCount tries in case of error.
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
var failedFunc = () => Promise.reject() | |
var maxCount = 3; | |
(function loopCall (maxCount, count) { | |
if (count == undefined) count = 0 | |
return failedFunc() | |
.catch((err) => { | |
count++ | |
if (count == maxCount) return Promise.reject(err) | |
return loopCall(maxCount, count) | |
}) | |
})(maxCount) | |
.then(() => { | |
console.log(`Succeeded`) | |
}, (err) => { | |
console.log(`Failed`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment