Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. function multipleAttempts(promiseGenerator, configuration) {
  2. return new Promise(function (resolve, reject) {
  3. promiseGenerator()
  4. .then(resolve)
  5. .catch(function (reason) {
  6. var attemptsLeft = configuration.attempts - 1;
  7. if (attemptsLeft === 0) {
  8. reject(reason);
  9. } else {
  10. setTimeout(function () {
  11. multipleAttempts(promiseGenerator, {
  12. attempts: attemptsLeft,
  13. interval: configuration.interval
  14. })
  15. .then(resolve, reject);
  16. }, configuration.interval);
  17. }
  18.  
  19. });
  20. });
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement