Skip to content

Instantly share code, notes, and snippets.

@kiwiandroiddev
Created February 7, 2016 15:33
Show Gist options
  • Select an option

  • Save kiwiandroiddev/0cd896a61742e955c5b9 to your computer and use it in GitHub Desktop.

Select an option

Save kiwiandroiddev/0cd896a61742e955c5b9 to your computer and use it in GitHub Desktop.
Exponential backoff with RxJs (modified sample code from docs)
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();
@sanderploegsma
Copy link

Nice, but what happens when the maximum amount of retries is reached? I don't think onError is called in this case, while I think it should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment