window

signature: window(windowBoundaries: Observable): Observable

Observable of values for window of time.

Examples

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 1s
const source = timer(0, 1000);
const example = source.pipe(window(interval(3000)));
const count = example.pipe(scan((acc, curr) => acc + 1, 0));
/*
  "Window 1:"
  0
  1
  2
  "Window 2:"
  3
  4
  5
  ...
*/
const subscribe = count.subscribe(val => console.log(`Window ${val}:`));
const subscribeTwo = example
  .pipe(mergeAll())
  .subscribe(val => console.log(val));

Additional Resources

:file_folder: Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/window.ts

Last updated