Skip to content

Instantly share code, notes, and snippets.

@khubo
Created May 23, 2021 01:39
Show Gist options
  • Save khubo/f22645b7bc49a7dc30a6b7532f6f138c to your computer and use it in GitHub Desktop.
Save khubo/f22645b7bc49a7dc30a6b7532f6f138c to your computer and use it in GitHub Desktop.
let allMessages = [];
function updateMessage() {
let jobQueue = [];
let running = false;
return function(message) {
// whenever the function gets called push the message to a job queue.
jobQueue.push(message);
if(!running) {
running = true;
setTimeout(() => {
allMessages = [...allMessages, ...jobQueue];
jobQueue = [];
running = false;
}, 100)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment