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 🙏

© 2024 – Pkg Stats / Ryan Hefner

child-pool

v1.2.1

Published

child_process pool implementation

Downloads

14

Readme

Child Pool

child_process pool implementation suporting:

  • Global and per-pool worker limits
  • Background vs. foreground execution mode
  • Integrated error handling

Usage

Pool

 var ChildPool = require('./child-pool');

ChildPool.isBackground(true);

var worker = new ChildPool(__dirname + '/child-worker', options);
worker.send({foo: 'bar'}, function() {
});

Options:

  • workers: Number of workers that might be spawned. Defaults to # CPUs.
  • keepAlive: Time duration in ms to keep idle workers alive. Defaults to 500ms.

#send(message, callback)

Queues message for the worker, calling callback upon competion.

callback will only be called once per message cycle. If the client sends out of band messages they will trigger an error event on the pool instance and may be handled as appropriate there.

#sendAll(message)

Broadcasts message to all live workers immediately.

As there is no callback associated with this event, workers receiving this message should not send return messages. Those that do will cause an error event on the pool instance.

Worker

A global worker object is declared within the worker context. This exposes 3 process.send wrappers that simplify data respones.

process.on('message', function(message) {
  worker.data({foo: 'bar'});
});

#data(data)

Send a data message to the parent.

#error(err)

Send a non-fatal error message to the parent. This may be an Error or string instance. In the later case the stack trace of the call will be associated with the message.

#fatal(err)

Send a fatal error message to the parent. This may be an Error or string instance. In the later case the stack trace of the call will be associated with the message. The parent will terminate the worker after receiving this message.

Global worker limit

Undermost circumstances, the library will not spawn more than the number of CPUs across the entire node instance. The exceptions are:

  • ChildPool.isBackground has been called with a truthy value

    Forces the library to not spawn more than #CPUs - 1. To ensure that there is a process open for interactive processes.

  • When there is only one CPU core

    The library will still spawn two workers.

The global worker limit constrains any values that might have been passed in the pool initialization options.

Bitdeli Badge