2.0.1 • Published 12 months ago

@inca/job-queue v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Simple Promise Queue

Highlights

  • 🔥 Zero dependencies
  • 🗜 Tidy and compact
  • 💻 ESM, works in browser
  • 🔬 Strongly typed

Usage

import { JobQueue } from '@inca/job-queue';

const jobQueue = new JobQueue({ concurrency: 1 });

async function sleep(ms: number) {
    await new Promise(r => setTimeout(r, ms));
}

const [
    res1,
    res2,
    res3,
] = Promise.all([
    jobQueue.run(() => sleep(10).then(() => 'foo')),
    jobQueue.run(() => sleep(10).then(() => 'bar')),
    jobQueue.run(() => sleep(10).then(() => 'baz')),
]);

// Only one promise runs at a time,
// each one waits for all previous to complete
assert.strictEqual(res1, 'foo');
assert.strictEqual(res2, 'bar');
assert.strictEqual(res3, 'baz');
2.0.1

12 months ago

2.0.0

12 months ago