Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function multipleAttempts(promiseGenerator, configuration) {
- return new Promise(function (resolve, reject) {
- promiseGenerator()
- .then(resolve)
- .catch(function (reason) {
- var attemptsLeft = configuration.attempts - 1;
- if (attemptsLeft === 0) {
- reject(reason);
- } else {
- setTimeout(function () {
- multipleAttempts(promiseGenerator, {
- attempts: attemptsLeft,
- interval: configuration.interval
- })
- .then(resolve, reject);
- }, configuration.interval);
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement