npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dispatchqueue

v0.7.6

Published

Swift's DispatchQueue recreated for Node.

Downloads

7

Readme

DispatchQueue

Swift's DispatchQueue recreated for Node.

Features

  • Central dispatch queue;
  • Configurable and hot-scaling of amount of threads;
  • Automatic restart of failed workers;
  • DispatchGroups;
  • A thread implementation, DispatchThread;
  • Terminate tasks which take longer than x ms.

Performance

To see the effects of implementing DispatchQueue, clone the repository and run npm run test:timings for a basic timing benchmark. To measure the average communication latency between the main thread and task threads, see npm run test:latency.

Installation

npm install dispatchqueue

const DispatchQueue = require("dispatchqueue");
// ...

Usage

// A thread amount of 1 can be configured for a FIFO/serial queue.
const path = "./path/to/worker.js";
const threadAmount = 5;
const dispatch = new DispatchQueue(path, { threadAmount });

Task creation

// Schedules a task to the queue.
dispatch
    .task({ /* data */ })
    .then(result => { /* result completion */ })
    .catch(error => { /* result issue */ });

Scaling

// Scales to a given amount of threads: the total amount of
// execution threads will be 8.
dispatch.scaleTo(8);

// Scales up or down by a given amount of threads: with the
// action above, there will be 5 total threads (8 + (-3) = 5).
dispatch.scale(-3);

// Suggestion: calculate the amount of threads your program needs
// depending on the average load. DispatchQueue can spawn one thread
// for each 500 requests per second, for example.
dispatch.scaleTo(Math.ceil(requestsPerSecond / 5e2));

Group management

// A group of dispatch queues can be created, and they are accessed
// using `.global()`.
const services = new DispatchQueue.Group({
    "main": {
        path: "./base/path/service_1.js",
        threadAmount: 3,
        dataContext: { ... } },
    "secondary": {
        path: "./base/path/service_2.js",
        threadAmount: 5,
        lazyInitialisation: true,
        logs: true }
});

services
    .global("main")
    .task({ /* data */ });
    // ...

Thread implementation

// A file at the thread path can use DispatchThread, which
// automatically ensures payload safety and other synchronisation.
class Thread extends DispatchQueue.Thread {

    // Automatic rejection after 20 milliseconds, default 300.
    static automaticRejectionTime = 20;

    onPayload(data) {
        const result = {
            ...data,
            context: this.dataContext,
            threadId: this.identifier };
        this.resolve(result); // or
        throw new Error("Task failed to execute");
    }
}

new Thread();

This module is licensed under Apache 2.0.