you can pass first
import { interval, fromEvent } from 'rxjs';
import { bufferToggle, mapTo } from 'rxjs/operators';
const click$ = fromEvent(document, 'click');
const opening$ = interval(3000);
const buffer$ = click$.pipe(bufferToggle(opening$,
// count: opening$ emit value
count => count % 2 ? interval(500) : null // when count is is Odd emit close after 0.5s
));
// result: when opening$ emit 2(Odd), will buffer all value between now and 0.5s late
Official Doc: rxjs.bufferToggle