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

smart-worker-pool

v1.0.0

Published

A smart worker pool for Node.js that allows using worker threads without separate files and supports direct library usage

Readme

Smart Worker Pool

A smart worker pool for Node.js that allows using worker threads without separate files and supports direct library usage.

npm version License: MIT

Features

  • 🚀 No separate worker files: Run functions in worker threads without creating separate JS files
  • 📚 Direct library usage: Use libraries directly in your worker threads
  • ⚙️ Configurable concurrency: Control the number of concurrent worker threads
  • 🔄 Automatic retries: Retry failed tasks automatically
  • ⏱️ Task timeouts: Set timeouts for long-running tasks
  • 🧹 Proper cleanup: Automatically terminates workers when done

Installation

npm install smart-worker-pool

Usage

Basic Example

import { SmartWorkerPool } from 'smart-worker-pool';

// Create a worker pool
const pool = new SmartWorkerPool();

// Run a function in a worker thread
const result = await pool.run(
  (data) => {
    // This code runs in a worker thread
    return data.x + data.y;
  },
  { x: 10, y: 20 }
);

console.log(result); // 30

// Shutdown the pool when done
await pool.shutdown();

Using Libraries

import { SmartWorkerPool } from 'smart-worker-pool';

// Create a worker pool with preloaded libraries
const pool = new SmartWorkerPool({
  preload: {
    // Format: alias: package-name
    lodash: 'lodash',
    moment: 'moment'
  }
});

// Use the libraries in the worker thread
const result = await pool.run(
  (data, libs) => {
    // libs contains the preloaded libraries
    const { lodash, moment } = libs;
    
    // Use lodash in the worker thread
    const items = lodash.range(1, data.count + 1);
    const sum = lodash.sum(items);
    
    // Use moment in the worker thread
    const now = moment().format('YYYY-MM-DD');
    
    return { sum, now };
  },
  { count: 5 }
);

console.log(result); // { sum: 15, now: '2023-04-01' }

// Shutdown the pool when done
await pool.shutdown();

Advanced Configuration

import { SmartWorkerPool } from 'smart-worker-pool';

// Create a worker pool with advanced options
const pool = new SmartWorkerPool({
  // Libraries to preload
  preload: {
    axios: 'axios',
    dayjs: 'dayjs'
  },
  // Maximum number of concurrent workers
  maxConcurrency: 4,
  // Maximum number of retries for failed tasks
  maxRetry: 3,
  // Timeout in milliseconds (5 seconds)
  taskTimeout: 5000,
  // Whether to terminate workers after each task
  terminateAfterTask: true
});

// ... use the pool

// Shutdown the pool when done
await pool.shutdown();

API Reference

SmartWorkerPool

Constructor Options

interface SmartWorkerPoolOptions {
  // Libraries to preload in the format { alias: 'package-name' }
  preload?: Record<string, string>;
  // Maximum number of concurrent workers (default: 4)
  maxConcurrency?: number;
  // Maximum number of retries for failed tasks (default: 0)
  maxRetry?: number;
  // Timeout in milliseconds for each task (default: 0, no timeout)
  taskTimeout?: number;
  // Whether to terminate workers after each task (default: true)
  terminateAfterTask?: boolean;
}

Methods

  • run<T, R>(fn: (data: T, libs: Record<string, any>) => R | Promise<R>, data: T): Promise<R>

    Runs a function in a worker thread.

    • fn: The function to run in the worker thread
    • data: The data to pass to the function
    • Returns a promise that resolves with the result of the function
  • shutdown(): Promise<void>

    Shuts down the worker pool, terminating all workers and rejecting queued tasks.

License

MIT