promise-retryer
provides an easy way to make promises retry based on exceptions or result validation
install
npm install promise-retryer
params
- delay (can be a number or function that returns a number, if its a function it gets called with an attempt argument)
- maxRetries (the maximum amount of retries)
- validate (validation promise)
- onError (callback function on errors, gets called with an error object and an attempt argument)
- onAttempt (callback function on attempts, gets called with an attempt argument)
- debug (enable verbose logging)
- name (this is useful for debugging purposes)
examples
heres a basic retry example
var PromiseRetryer = Promise; PromiseRetryer;
and heres a little more advanced example with validation and custom delays
var PromiseRetryer = Promise; PromiseRetryer;