skip to content

windowWhen

 

windowWhen will emit a new substream of values from the source stream, every time the stream returned by provided function emits:

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

timer(0, 4).pipe(
    // take 10 values
    take(10),
  
    // open a window every 10ms
    windowWhen(() => timer(10)),
  
    // manage with the substream
    // that emits events inside the window
    mergeMap(substream =>
      substream.pipe(count())
    )
  )
  .subscribe(rxObserver());
0msstartcomplete33 33 22 22