skip to content

timeout

 

Timeout operator will ensure that time gap between emissions won't be longer than defined duration. If source doesn't emit longer then duration — timeout will raise an error on stream:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const { rxObserver } = require('api/v0.3');
const { from, timer } = require('rxjs');
const { delayWhen, timeout } = require('rxjs/operators');

// create a source that will emit at 0, 10, 20 and 45ms
const source$ = from([ 0, 10, 20, 45 ])
  .pipe(
    delayWhen(x => timer(x))
  );

// set maximum gap using `timeout`
const result$ = source$.pipe(
  timeout(20)
);


source$.subscribe(rxObserver());
result$.subscribe(rxObserver());

0msstartcomplete00 1010 2020 4545 start00 1010 2020 TimeoutError: Timeout has occurred!