timeout
Errors if Observable does not emit a value in given time span.
Parameters
Returns
MonoTypeOperatorFunction<T>
: Observable that mirrors behaviour of source, unless timeout checks fail.
Description
Timeouts on Observable that doesn't emit values fast enough.
timeout
operator accepts as an argument either a number or a Date.
If number was provided, it returns an Observable that behaves like a source
Observable, unless there is a period of time where there is no value emitted.
So if you provide 100
as argument and first value comes after 50ms from
the moment of subscription, this value will be simply re-emitted by the resulting
Observable. If however after that 100ms passes without a second value being emitted,
stream will end with an error and source Observable will be unsubscribed.
These checks are performed throughout whole lifecycle of Observable - from the moment
it was subscribed to, until it completes or errors itself. Thus every value must be
emitted within specified period since previous value.
If provided argument was Date, returned Observable behaves differently. It throws if Observable did not complete before provided Date. This means that periods between emission of particular values do not matter in this case. If Observable did not complete before provided Date, source Observable will be unsubscribed. Other than that, resulting stream behaves just as source Observable.
timeout
accepts also a Scheduler as a second parameter. It is used to schedule moment (or moments)
when returned Observable will check if source stream emitted value or completed.
Examples
Check if ticks are emitted within certain timespan
Use Date to check if Observable completed