iarna/run-queue

Fix example code in `README.md`

Opened this issue · 0 comments

Description

I'd like to propose a fix for the example code in README.md.

Example

const RunQueue = require('run-queue');

// Setup:
const queue = new RunQueue({ maxConcurrency: 1 });
const finished = [];
const example = (num) =>
  new Promise((resolve) => {
    setTimeout(() => {
      finished.push(num);
      resolve();
    }, 5 - Math.abs(num));
  });

// Adding to queue:
queue.add(1, example, [-1]);
for (let i = 0; i < 5; ++i) {
  queue.add(0, example, [i]);
}

// Getting results:
queue.run().then(() => {
  console.log(finished);
});