Example 1: Open window specified by inner observable
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+import { timer, interval } from 'rxjs';import { window, scan, mergeAll } from 'rxjs/operators';//emit immediately then every 1sconst source = timer(0, 1000);const example = source.pipe(window(interval(3000)));const count = example.pipe(scan((acc, curr) => acc + 1, 0));/*"Window 1:"012"Window 2:"345...*/const subscribe = count.subscribe(val => console.log(`Window ${val}:`));const subscribeTwo = example.pipe(mergeAll()).subscribe(val => console.log(val));
window
📰 - Official docs
Split an RxJS observable with window
🎥 💵 - André Staltz
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/window.ts