Created
January 7, 2019 23:30
-
-
Save christianscott/7704e5fd174f837a4a3c88c03992eb06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function bufferStream( | |
handler: (events: Event[]) => void, | |
timeMs: number, | |
): (event: Event) => void { | |
let timeout: number = null; | |
let events: Event[] = []; | |
return (event: Event) => { | |
if (timeout != null) { | |
clearTimeout(timeout); | |
} | |
events.push(event); | |
timeout = setTimeout(() => { | |
handler(events); | |
events = []; | |
}, timeMs); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment