Created
May 23, 2021 01:39
-
-
Save khubo/f22645b7bc49a7dc30a6b7532f6f138c to your computer and use it in GitHub Desktop.
This file contains 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
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