Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Last active March 5, 2020 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mafintosh/b6db176225ea9ad927366419931ea445 to your computer and use it in GitHub Desktop.
Save mafintosh/b6db176225ea9ad927366419931ea445 to your computer and use it in GitHub Desktop.
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