Last active
August 18, 2020 07:22
-
-
Save leihuang23/1e0dfed84db4264424926dc0b9bd88d0 to your computer and use it in GitHub Desktop.
Tail call optimization
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 timeout = null; | |
const queue = new Set(); | |
function process() { | |
for (const task of queue) { | |
task(); | |
} | |
queue.clear(); | |
timeout = null; | |
} | |
function enqueue(task) { | |
if (timeout === null) timeout = setTimeout(process, 0); | |
queue.add(task); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment