bufferCount

signature: bufferCount(bufferSize: number, startBufferEvery: number = null): Observable

Example 1: Collect buffer and emit after specified number of values
Example 2: Overlapping buffers
  1. import { interval } from 'rxjs/observable/interval';
  2. import { bufferCount } from 'rxjs/operators';
  3. //Create an observable that emits a value every second
  4. /*
  5. bufferCount also takes second argument, when to start the next buffer
  6. 1st interval value:
  7. buffer 1: [0]
  8. 2nd interval value:
  9. buffer 1: [0,1]
  10. buffer 2: [1]
  11. 3rd interval value:
  12. buffer 1: [0,1,2] Buffer of 3, emit buffer
  13. 4th interval value:
  14. buffer 2: [1,2,3] Buffer of 3, emit buffer
  15. buffer 3: [2, 3]
  16. buffer 4: [3]
  17. */
  18. const bufferEveryOne = source.pipe(bufferCount(3, 1));
  19. //Print values to console
  20. const subscribe = bufferEveryOne.subscribe(val =>

Additional Resources