
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
cluster-vir
Advanced tools
Simplifies running a script across multiple workers. This only works in Node.js (not in the browser) because it relies on Node.js's built-in cluster module.
npm i cluster-vir
See full docs here: https://electrovir.github.io/cluster-vir
The main export from this package is runInCluster. Pass it a callback to be executed on each worker. Here's an example of how to use it:
import {createServer} from 'node:http';
import {runInCluster} from 'cluster-vir';
/**
 * In the primary thread the output of `runInCluster` gives you an instance of `ClusterManager`
 * which can be used to access all child nodes. In the worker threads it gives you an instance of
 * `WorkerRunner` which can be used to access the worker.
 */
const runner = runInCluster(
    ({worker}) => {
        /**
         * Do the worker actions here. In this example, each worker is listening to a port as an
         * HTTP server.
         */
        /**
         * Cluster workers can share a TCP connection, so an HTTP server can be handled by (and will
         * be load-balanced between) multiple workers (or threads).
         */
        const server = createServer((request, response) => {
            response.writeHead(200);
            response.end(`hello there ${worker.process.pid}`);
        }).listen(8000);
        return () => {
            /**
             * Do cleanup work in here. In this case, we're closing the HTTP server. Note that a
             * cleanup callback cannot be async.
             */
            server.close();
        };
    },
    {
        /**
         * Indicates that all child workers should be started immediately. If set to `false`, you
         * must call `runner.startWorkers()` to start them, giving you time to attach any listeners
         * you may need.
         */
        startWorkersImmediately: true,
    },
);
runInCluster finishes, you must manually kill them with worker.kill() or process.exit().respawnWorkers has not been set to true, the cluster manager will automatically terminate itself as well.if or switch to focus on your messages.FAQs
Makes it easy to distribute arbitrary scripts across multiple workers.
We found that cluster-vir demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.