signature: timeoutWith(due: number | Date, withObservable: ObservableInput, scheduler: SchedulerLike = async): OperatorFunction
( StackBlitz )
// RxJS v6+
import { of } from 'rxjs';
import { timeoutWith, delay, concatMap } from 'rxjs/operators';
const fakeRequest = delayTime => of('!response!').pipe(delay(delayTime));
const requestTimeoutLogger = of('logging request timeout');
const timeoutThreshold = 1000;
of(timeoutThreshold + 1, timeoutThreshold - 1, timeoutThreshold + 3)
.pipe(
concatMap(e =>
fakeRequest(e).pipe(timeoutWith(timeoutThreshold, requestTimeoutLogger))
)
)
.subscribe(console.log);
/*
OUTPUT:
logging request timeout
!response!
logging request timeout
*/
- timeoutWith 📰 - Official Docs
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/timeoutWith.ts