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 🙏

© 2025 – Pkg Stats / Ryan Hefner

simple-worker-thread-queue

v1.0.8

Published

Simple Node.js queue that executes jobs asynchronously with worker threads

Readme

Simple Worker Thread Queue

Provides an simply in-memory queue that manages the processing of jobs. Jobs are processed asychronously with Node.js Worker Threads.

Queue behavior is as follows:

  • Queue exists only in-memory, not persisted
  • Jobs begin processing immediately when added
  • Jobs are processed sequentially one at a time, unless the CONCURRENT_WORKER_THREADS configuration in a .env file is greater than 1
  • Optional completion callbacks can be provided to Jobs or Batches to track processing completion

Install

To install as a dependency in your project:

npm install simple-worker-thread-queue

Use

Typescript examples are available in ./examples/typescript, but the basic steps are:

  1. Define a custom Job processing function in a seperate file and export it as processJob.
// CustomWorker.js
export async function processJob (jobOptions, job) {
  const result = {
    message: `Hello ${jobOptions.name}`,
  };
  // result will be saved to the job data
  return result;
};
  1. Create a Queue in your project file and pass the absolute path to the file exporting processJob.
import { Queue } from 'simple-worker-thread-queue';

const queue = new Queue({
  processJobExportPath: path.join(__dirname, './CustomWorker.js')
});
  1. Add a Job to the Queue. Monitor Job completion with a completionCallback function.
const completionCallback = async (completedJob) => {
  console.log(`job ${completedJob.getId()} completed with result: ${completedJob.getData().message}`);
};

const jobOptions = {
  name: 'Taylor',
  completionCallback,
};

const job = queue.add(jobOptions);

Batches

Jobs can be grouped together into a Batch. By supplying a batch completion callback function, consuming services can be nofitied when the processing of the batched jobs is complete.

import { Batch } from 'simple-worker-thread-queue';

const completionCallback = async function (completedBatch) {
  console.log(`batch ${completedBatch.getId()} completed with ${completedBatch.getJobs().length} jobs`);
}
const batch = new Batch(completionCallback);

// add jobs to queue with batch parameter
const job1 = queue.addToBatch(job1Options, batch);
const job2 = queue.addToBatch(job2Options, batch);

Inspiration

When AWS announced it would be discontinuing support for their Elastic Transcoder service, I created a small REST-based service to replace it. As part of this service I needed simple job queuing, with job processing offloaded so the main thread could handle further REST requests.

Existing queuing solutions like BullMQ were feature rich but overkill. I spun the queueing code I created off as a seperate npm package incase it could be used else-where.