Boundary-based buffering
The most powerful overload of the buffer() operator is the one that accepts another Observable as a boundary argument: buffer(Observable<B> boundary). It does not matter what type this other Observable emits. All that matters is that every time it emits something, it will use the timing of that emission as the buffer cutoff. In other words, the arbitrary occurrence of emissions of another Observable will determine when to slice each buffer.
For example, we can perform our previous example with 300-millisecond emissions buffered every 1 second using this technique. We can have an Observable.interval() of 1 second serve as the boundary for our Observable.interval(), emitting every 300 milliseconds, as shown in the following ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access