adelarosab
2/16/2017 - 9:34 PM

Promise retry snippet

Promise retry snippet

Promise.retry = function(executor, times) {
  const step = () => new Promise(executor);
  let promise = step();
  
  for(let i = 1; i < times; i++) { 
    promise = promise.catch(step);
  }
  
  return promise;
};