Returns the source observable sequence or the other observable sequence if dueTime elapses.
dueTime
(Date | Number): Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.[other]
(Observable
|Promise
|string
): Observable sequence or Promise to return in case of a timeout. If a string is specified, then an error will be thrown with the given error message. If not specified, a timeout error throwing sequence will be used.[scheduler=Rx.Observable.timeout]
(Scheduler
): Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.
(Observable
): An observable sequence with time interval information on values.
/* With no other */
var source = Rx.Observable
.return(42)
.delay(5000)
.timeout(200);
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Error: Error: Timeout
/* With message */
var source = Rx.Observable
.return(42)
.delay(5000)
.timeout(200, 'Timeout has occurred.');
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Error: Error: Timeout has occurred.
/* With an observable */
var source = Rx.Observable
.return(42)
.delay(5000)
.timeout(200, Rx.Observable.empty());
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Completed
/* With a Promise */
var source = Rx.Observable
.return(42)
.delay(5000)
.timeout(200, Promise.resolve(42));
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
File:
Dist:
Prerequisites:
NPM Packages:
NuGet Packages:
Unit Tests: