retryWhen
Repeats the source observable sequence on error when the notifier emits a next value. If the source observable errors and the notifier completes, it will complete the source sequence
Arguments
notificationHandler(Function): A handler that is passed an observable sequence of errors raised by the source observable and returnsand observable that either continues, completes or errors. This behavior is then applied to the source observable.
Returns
(Observable): An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully or is notified to error or complete.
Example: delayed retry
var count = 0;
var source = Rx.Observable.interval(1000)
.map(function(n) {
if(n === 2) {
throw 'ex';
}
return n;
})
.retryWhen(function(errors) {
return errors.delay(200);
})
.take(6);
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 0
// => Next: 1
// 200 ms pass
// => Next: 0
// => Next: 1
// 200 ms pass
// => Next: 0
// => Next: 1
// => Error: 'ex'Example: Erroring an observable after 2 failures
Example: Completing an observable after 2 failures
An incremental back-off strategy for handling errors:
Last updated
Was this helpful?