Last active
March 5, 2020 16:43
-
-
Save mafintosh/b6db176225ea9ad927366419931ea445 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
const queue = new Signal() | |
const done = new Signal() | |
const pending = [] | |
async function runQueue () { | |
while (!pending.length && await queue.wait()); | |
const current = pending | |
pending = [] | |
await process(current) | |
done.notify() | |
} | |
async function addToQueue (job) { | |
pending.push(job) | |
queue.notify() | |
return done.wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment