UNPKG

sflow

Version:

sflow is a powerful and highly-extensible library designed for processing and manipulating streams of data effortlessly. Inspired by the functional programming paradigm, it provides a rich set of utilities for transforming streams, including chunking, fil

16 lines (15 loc) 409 B
export function debounces<T>(t: number) { let id: ReturnType<typeof setTimeout> | null = null; return new TransformStream<T, T>({ transform: async (chunk, ctrl) => { if (id) clearTimeout(id); id = setTimeout(() => { ctrl.enqueue(chunk); id = null; }, t); }, flush: async () => { while (id) await new Promise((r) => setTimeout(r, t / 2)); }, }); }