Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clusterhub

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clusterhub - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

67

lib/hub.js

@@ -62,3 +62,3 @@ const cluster = require('cluster');

this.subscribe = this.on;
this.removeLIstener = this.off;
this.removeListener = this.off;
this.unsubscribe = this.off;

@@ -209,2 +209,16 @@

/**
* @param {string} event
* @param {Function(...args)} listener
* @param {boolean} append
*/
_on(event, listener, append) {
if (!this._listeners.has(event)) this._listeners.set(event, []);
this._listeners.get(event)[append ? 'push' : 'unshift'](listener);
if (isWorker) {
this._sendMaster({ cmd: commands.ON, event });
}
}
/**
* Starts listening to an event within the hub.

@@ -217,8 +231,14 @@ *

on(event, listener) {
if (!this._listeners.has(event)) this._listeners.set(event, []);
this._listeners.get(event).push(listener);
this._on(event, listener, true);
}
if (isWorker) {
this._sendMaster({ cmd: commands.ON, event });
}
/**
* Adds the listener at the beginner of the list of listeners,
* calling it before other listeners.
*
* @param {string} event
* @param {Function(...args)} listener
*/
prependListener(event, listener) {
this._on(event, listener, false);
}

@@ -255,4 +275,5 @@

* @param {Function(...args)} listener
* @param {boolean} append
*/
many(n, event, listener) {
_many(n, event, listener, append) {
const wrapper = (...args) => {

@@ -263,6 +284,26 @@ if (--n === 0) this.off(event, listener);

wrapper.listener = listener;
this.on(event, wrapper);
this[append ? 'on' : 'prependListener'](event, wrapper);
}
/**
* Listens for n number of the event and then stops listening.
*
* @param {number} n
* @param {string} event
* @param {Function(...args)} listener
*/
many(n, event, listener) {
this._many(n, event, listener, true);
}
/**
* @param {number} n
* @param {string} event
* @param {Function(...args)} listener
*/
prependManyListener(n, event, listener) {
this._many(n, event, listener, false);
}
/**
* Shortcut for `many(1, event, listener)`

@@ -274,6 +315,14 @@ *

once(event, listener) {
this.many(1, event, listener);
this._many(1, event, listener, true);
}
/**
* @param {string} event
* @param {Function(...args)} listener
*/
prependOnceListener(event, listener) {
this._many(1, event, listener, false);
}
/**
* Removes all listeners for the event.

@@ -280,0 +329,0 @@ *

2

package.json

@@ -11,3 +11,3 @@ {

],
"version": "1.0.1",
"version": "1.1.0",
"repository": {

@@ -14,0 +14,0 @@ "type": "git",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc