bufferCount
signature: bufferCount(bufferSize: number, startBufferEvery: number = null): Observable
Example 1: Collect buffer and emit after specified number of values
Example 2: Overlapping buffers
import { interval } from 'rxjs/observable/interval';
import { bufferCount } from 'rxjs/operators';
//Create an observable that emits a value every second
/*
bufferCount also takes second argument, when to start the next buffer
1st interval value:
buffer 1: [0]
2nd interval value:
buffer 1: [0,1]
buffer 2: [1]
3rd interval value:
buffer 1: [0,1,2] Buffer of 3, emit buffer
4th interval value:
buffer 2: [1,2,3] Buffer of 3, emit buffer
buffer 3: [2, 3]
buffer 4: [3]
*/
const bufferEveryOne = source.pipe(bufferCount(3, 1));
//Print values to console
const subscribe = bufferEveryOne.subscribe(val =>
Additional Resources