Last active
August 29, 2015 14:15
-
-
Save dburles/5a791b2d3867e5282639 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
var timeout; | |
var batch = []; | |
batcher = function(attributes) { | |
batch.push(attributes); | |
if (! timeout) { | |
// send whatever we have in the queue after 5 seconds | |
timeout = setTimeout(function() { | |
console.log('sending a batch of ' + batch.length + '...'); | |
// do something | |
batch = []; | |
timeout = false; | |
}, 5000); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment