Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Last active March 5, 2020 16:43
Show Gist options
  • Select an option

  • Save mafintosh/b6db176225ea9ad927366419931ea445 to your computer and use it in GitHub Desktop.

Select an option

Save mafintosh/b6db176225ea9ad927366419931ea445 to your computer and use it in GitHub Desktop.

Revisions

  1. mafintosh revised this gist Mar 5, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions process-queue.js
    Original file line number Diff line number Diff line change
    @@ -13,5 +13,6 @@ async function runQueue () {

    async function addToQueue (job) {
    pending.push(job)
    queue.notify()
    return done.wait()
    }
  2. mafintosh created this gist Mar 5, 2020.
    17 changes: 17 additions & 0 deletions process-queue.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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)
    return done.wait()
    }