Learn RxJS
Search…
windowTime

signature: windowTime(windowTimeSpan: number, windowCreationInterval: number, scheduler: Scheduler): Observable

Observable of values collected from source for each provided time span.

Examples

Example 1: Open new window every specified duration
1
// RxJS v6+
2
import { timer } from 'rxjs';
3
import { windowTime, tap, mergeAll } from 'rxjs/operators';
4
5
//emit immediately then every 1s
6
const source = timer(0, 1000);
7
const example = source.pipe(
8
//start new window every 3s
9
windowTime(3000),
10
tap(_ => console.log('NEW WINDOW!'))
11
);
12
13
const subscribeTwo = example
14
.pipe(
15
//window emits nested observable
16
mergeAll()
17
/*
18
output:
19
"NEW WINDOW!"
20
0
21
1
22
2
23
"NEW WINDOW!"
24
3
25
4
26
5
27
*/
28
)
29
.subscribe(val => console.log(val));
Copied!

Additional Resources