Demo: bufferToggle
bufferTogle operator takes two inputs.
- When the first one emits it starts buffering the incoming items into an array and also triggers the closing observable which is the 2nd parameter.
- When the closing observable emits, it stops buffering and emits the array of collected inputs as seen in the demo.
bufferToggle(openingObservable,
(v) => dependentClosingObservable)
//Emit 12 items every 1 sec, starting 0.5 sec
let input = timer(500,1000).pipe(take(12));
//buffering opens every 4 sec starting at the beginning,
//closing observable closes it in next 3 sec
let process = bufferToggle(timer(0, 4000),()=>timer(3000));
let output=input.pipe(process).subscribe(v=>console.log(v))