Qretry
Qretry creates a Promise from the call function with a retry strategy.
Checkout the Annotated Source Code
Installation
bower install qretry
Also available on NPM.
Usage
Qretry
takes an action function and returns a Promise of result where result is the first successful value resulting from the action call or a failure if the retry reached his limit (this failure Promise is the last failed Promise from call).
Qretry(action: (=> R or Promise[R]), options: Object) => Promise[R]
options
is an object with optional parameters:
maxRetry
(Number) optional: set the maximum retry (default is 5)interval
(Number) optional: set the initial interval in milliseconds between the first and the second call. (default is 500)intervalMultiplicator
(Number >= 1) optional: set the multiplicator which increase the interval through tries. (default is 1.5)
Simple example
var promise = ;
Example with Qajax
;
Random example
var startTime = ;;
will eventually log:
action at 0s
action at 0.101s
action at 0.303s
action at 0.704s
action at 1.506s
action at 3.108s
action at 6.31s
<success!>
if action fail 6 times and succeed at the 7th time.