dpwm-queue
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

dpwm-queue

A simple array-backed queue with parallel worker-based consumption. It is useful for io-bound tasks that can be parallelised, such as parallel downloads using p workers.

Usage

Putting items into the queue

Items are put in either at construction:

import { Queue } from "dpwm-queue";
const q = new Queue([1, 2, 3]);

or using push:

import { Queue } from "dpwm-queue";
const q = new Queue();
q.push(1);
q.push(2);

Iterating over the queue

Items are never removed; they are designed to be iterated over using pForEach.

pForEach is a parallel forEach. It takes an async function as a callback.

Warning: this does not free up memory as items are consumed.

import { Queue } from "dpwm-queue";
const q = new Queue([1, 2, 3]);
q.close(); // The queue can be left open, which can be useful.

await q.pForEach(
    async (x, n) => {},
    2 // Number of workers. Default is 1.
    );

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i dpwm-queue

    Weekly Downloads

    0

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    14.8 kB

    Total Files

    19

    Last publish

    Collaborators

    • dpwm