Last active
May 28, 2016 15:48
-
-
Save tweinfeld/825a45a380cb53f5b4d160d4767ea6ba 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
function createLogger(writer = console.log.bind(console), bufferThreshold = 100, delay = 5000){ | |
let buf = [], timer; | |
const dispose = ()=>{ writer(buf.splice(0)); }; | |
return function(obj){ | |
buf.push(obj); | |
clearTimeout(timer); | |
(buf.length >= bufferThreshold ? dispose() : timer = setTimeout(dispose, delay)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment