windowTime

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

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

windowTime - 图1

Examples

Example 1: Open new window every specified duration

( StackBlitz |
jsBin |
jsFiddle )

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

Additional Resources


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