npm

@ars9/easy-queue
TypeScript icon, indicating that this package has built-in type declarations

0.10.2 • Public • Published

@ars9/easy-queue

A simple promise-based job queue with concurrency.

Example:

// import { Queue } from '@ars9/easy-queue'); /* Correct Typescript import */
const { Queue } = require('@ars9/easy-queue');

// Create a queue instance with concurrency 3
const q = new Queue(3);

// Add some jobs to queue
q.enqueue(() => console.log(`I'm doing my part`));
q.enqueue(() => console.log(`Thanks me too`));
q.enqueue(() => console.log(`And my axe!`));

// By default, exceptions are handled, but silenced. You can attach a custom handler.
q.onError((error) => console.error(error));

// Start execution. This method will be implicitly called in `wait` if omitted.
q.start();

// Wait for execution. Starts queue if needed.
q.wait().then(() => console.log(`Done`));

// Console output:
/*
 I'm doing my part
 Thanks me too
 And my axe!
 Done
*/

Package Sidebar

Install

npm i @ars9/easy-queue

Weekly Downloads

1

Version

0.10.2

License

ISC

Unpacked Size

19.7 kB

Total Files

11

Last publish

Collaborators

  • ars9