Created
June 30, 2016 03:53
-
-
Save codyromano/64421db37a29cdd1a70e6fce1fb4d255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example | |
| let backoff = new Backoff({ | |
| timeout: 5000, | |
| backoffExponent: 2, | |
| attempts: 10, | |
| jitterCap: 1000 * 60 * 20 // 20 minutes | |
| }); | |
| backoff.exec(function(markAsDone, forceRetry, forceFailure) { | |
| /* Some async process that might fail, in which | |
| case you would want to retry. A network request is a | |
| prime example. The request will automatically retry if | |
| it reaches the timeout threshold you specified. | |
| Alternatively, you can call forceRetry(). | |
| Use markAsDone() to indicate that the process has | |
| finished succcessfully and forceFailure() to give up | |
| on the process permanently. */ | |
| }).done(function(a, b) { | |
| /* The done and failure callbacks are optional and they | |
| both accept an arbitrary list of arguments */ | |
| console.log(a, b); | |
| }).fail(function() { | |
| console.log('failure'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment