Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.
[firstTimeout=Rx.Observable.never()]
(Observable
): Observable sequence that represents the timeout for the first element. If not provided, this defaults toRx.Observable.never()
.timeoutDurationSelector
(Function
): Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.[other=Rx.Observable.throw]
(Scheduler
):Sequence to return in case of a timeout. If not provided, this is set toObservable.throw
(Observable
): The source sequence switching to the other sequence in case of a timeout.
/* without a first timeout */
var array = [
200,
300,
350,
400
];
var source = Rx.Observable
.for(array, function (x) {
return Rx.Observable.timer(x);
})
.map(function (x, i) { return i; })
.timeoutWithSelector(function (x) {
return Rx.Observable.timer(400);
});
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: 2
// => Error: Error: Timeout
/* With no other */
var array = [
200,
300,
350,
400
];
var source = Rx.Observable
.for(array, function (x) {
return Rx.Observable.timer(x);
})
.map(function (x, i) { return i; })
.timeoutWithSelector(Rx.Observable.timer(250), function (x) {
return Rx.Observable.timer(400);
});
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: 2
// => Error: Error: Timeout
/* With other */
var array = [
200,
300,
350,
400
];
var source = Rx.Observable
.for(array, function (x) {
return Rx.Observable.timer(x);
})
.map(function (x, i) { return i; })
.timeoutWithSelector(Rx.Observable.timer(250), function (x) {
return Rx.Observable.timer(400);
}, Rx.Observable.return(42));
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: 2
// => Next: 42
// => Completed
File:
Dist:
Prerequisites:
NPM Packages:
NuGet Packages:
Unit Tests: