Created
February 7, 2016 15:33
-
-
Save kiwiandroiddev/0cd896a61742e955c5b9 to your computer and use it in GitHub Desktop.
Exponential backoff with RxJs (modified sample code from docs)
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
| var Rx = require('rx') | |
| var MAX_RETRIES = 4 | |
| Rx.Observable.throw(new Error("always fails")) | |
| .retryWhen(function (errors) { | |
| return Rx.Observable.zip( | |
| Rx.Observable.range(1, MAX_RETRIES), errors, function (i, e) { return i }) | |
| .flatMap(function (i) { | |
| console.log("delay retry by " + i + " second(s)"); | |
| return Rx.Observable.timer(i * 1000); | |
| }); | |
| }).subscribe(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, but what happens when the maximum amount of retries is reached? I don't think
onErroris called in this case, while I think it should be.