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
notificationHandler
(Function
): A handler that is passed an observable sequence of errors raised by the source observable and returns and observable that either continues, completes or errors. This behavior is then applied to the source observable.
(Observable
): An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully or is notified to error or complete.
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'
var count = 0;
var source = Rx.Observable.interval(1000)
.map(function(n) {
if(n === 2) {
throw 'ex';
}
return n;
})
.retryWhen(function(errors) {
return errors.scan(0, function(errorCount, err) {
if(errorCount >= 2) {
throw err;
}
return errorCount + 1;
});
});
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 0
// => Next: 1
// => Next: 0
// => Next: 1
// => Error: 'ex'
var count = 0;
var source = Rx.Observable.interval(1000)
.map(function(n) {
if(n === 2) {
throw 'ex';
}
return n;
})
.retryWhen(function(errors) {
return errors.scan(0, function(errorCount, err) {
return errorCount + 1;
}).takeWhile(function(errorCount) {
return errorCount < 2;
});
});
var subscription = source.subscribe(
function (x) {
console.log('Next: ' + x);
},
function (err) {
console.log('Error: ' + err);
},
function () {
console.log('Completed');
});
// => Next: 0
// => Next: 1
// => Next: 0
// => Next: 1
// => Completed
File:
Dist:
Prerequisites:
- None
NPM Packages:
NuGet Packages:
Unit Tests: