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

@elum/cluster

v0.0.7

Published

Promise/Callback communication between main and cluster process

Downloads

156

Readme

@elum/cluster

Language: RU | EN

Installation

YARN

yarn add @elum/cluster

NPM

npm i -s @elum/cluster

Getting Started

Cluster

Cluster this is class for created child process.

It wraps default events and methods from node:cluster for simple interactions between the main process and the child.

Callback from argument Cluster is body to child process.


cluster :

first argument in callback has an initialized from Cluster.


events :

function that accepts a callback to handle events from the Master. Сallback receives events that are not waiting for a response.


import { Cluster } from "@elum/cluster"

new Cluster((cluster, events) => {

	events((
		type, // type events 
		value, // data events
		reply // function on send response
	) => { reply({ result: true }) });

	const result = await cluster.send("CLIENT_ADD", { clientId: 1 });
		// result - response from Master

	cluster.send("CLIENT_ADD", { clientId: 1 }, (data) => {
		// data - response from Master
	})

}).start();

Master

Master this is class for created main process.

It wraps default events and methods from node:cluster for simple interactions between the main process and the child.

Callback from argument Cluster is body to main process.


master

first argument in callback has an initialized from Master.


events

function that accepts a callback to handle events from the Master. Сallback receives events that are not waiting for a response.


import { Master } from "@elum/cluster"

new Master((master, events) => {

	events((
		type, // type events 
		value, // data events
		reply // function on send response
	) => { reply({ result: true }) });
    
    const cluster = master.newCluster(); // created new cluster

    // send request and get promise response
	const result = await master.send(cluster, "CLIENT_ADD", { clientId: 1 });
		// result - response from Cluster

    // send request and get callback response
	master.send(cluster, "CLIENT_ADD", { clientId: 1 }, (data) => {
		// data - response from Cluster
	})

}).start();

Example

/** ./index.js */

import process from  "node:process";
import cluster from  "cluster";

try {
	cluster.isPrimary  ?
		import("Master") :
		import("Cluster")
}
catch (error) {
	console.log(error);
	process.exit(1);
}
/** ./Cluster.js */

import { Cluster } from "@elum/cluster";
new Cluster((cluster, events) => {
    events((type, value, reply) => {
	    switch(type) {
		    case "MASTER_EVENTS": reply({ result: true }); break;
		}
	})
	const result = await cluster.send("CLUSTER_EVENTS", { title: "Cluster NodeJS" });
	// result = { data: { access: true } }
}).start();
/** ./Master.js */

import { Master } from "@elum/cluster";
new Master((master, events) => {
    events((cluster, type, value, reply) => {
	    switch(type) {
		    case "CLUSTER_EVENTS": reply({ data: { access: true } }); break;
		}
	})
    const cluster = master.newCluster();
	const result = await master.send(cluster, "MASTER_EVENTS", { clientId: 1 });
	// result = { result: true }
	
}).start();

TypeScript

Cluster and Master accept generic interfaces for both Master and Cluster. The user interface must extends from the prepared type.

import {
	Cluster,
	Master,
	BridgeCluster,
	BridgeMaster
} from "@elum/cluster";

interface CustomBridgeCluster extends BridgeCluster {
	"CLUSTER_EVENTS": [
		{ title: string }, // request type on first index
		{ 
			data: {
				access: boolean;
			} 
		}  // response type on second index
	]
}

interface CustomBridgeMaster extends BridgeMaster {
	"MASTER_EVENTS": [
		{ clientId: number }, // request type on first index
		{ result: boolean }  // response type on second index
	]
}

new Cluster<CustomBridgeMaster,CustomBridgeCluster>((cluster, events) => {
	events((type, value, reply) => ***)
	const result = await cluster.send("CLUSTER_EVENTS", { title: "Cluster NodeJS" });
	// result = { data: { access: true } }
}).start();

new Master<CustomBridgeMaster,CustomBridgeCluster>((master, events) => {
    events((cluster, type, value, reply) => ***);
    const cluster = master.newCluster();
	const result = await master.send(cluster, "MASTER_EVENTS", { clientId: 1 });
	// result = { result: true }
	
}).start();