Learn RxJS
Search…
window

signature: window(windowBoundaries: Observable): Observable

Observable of values for window of time.

Examples

Example 1: Open window specified by inner observable
1
// RxJS v6+
2
import { timer, interval } from 'rxjs';
3
import { window, scan, mergeAll } from 'rxjs/operators';
4
5
//emit immediately then every 1s
6
const source = timer(0, 1000);
7
const example = source.pipe(window(interval(3000)));
8
const count = example.pipe(scan((acc, curr) => acc + 1, 0));
9
/*
10
"Window 1:"
11
0
12
1
13
2
14
"Window 2:"
15
3
16
4
17
5
18
...
19
*/
20
const subscribe = count.subscribe(val => console.log(`Window ${val}:`));
21
const subscribeTwo = example
22
.pipe(mergeAll())
23
.subscribe(val => console.log(val));
Copied!

Additional Resources

Last modified 2yr ago