Skip to content

Instantly share code, notes, and snippets.

@dburles
Last active August 29, 2015 14:15
Show Gist options
  • Save dburles/5a791b2d3867e5282639 to your computer and use it in GitHub Desktop.
Save dburles/5a791b2d3867e5282639 to your computer and use it in GitHub Desktop.
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