UNPKG

@lifaon/rx-js-light

Version:

Blazing fast Observables

25 lines (24 loc) 663 B
import {createTimeout} from "../../../../../../../../misc/timer/create-timeout.mjs"; export function bufferTimeObservable(subscribe, duration) { return emit => { let currentBuffer = []; let abortTimeout = null; const unsubscribe = subscribe(value => { currentBuffer.push(value); if (abortTimeout === null) { abortTimeout = createTimeout(() => { abortTimeout = null; const buffer = currentBuffer; currentBuffer = []; emit(buffer); }, duration); } }); return () => { unsubscribe(); if (abortTimeout !== null) { abortTimeout(); } }; }; }