clusterhub
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -40,3 +40,3 @@ const cluster = require('cluster'); | ||
const hub = hubs.get(msg.hub); | ||
let db, result, fn; | ||
let db, result; | ||
parseFuncs(hub, msg, worker); | ||
@@ -80,6 +80,3 @@ switch (msg.cmd) { | ||
case commands.FN: | ||
fn = hub._funcs.get(msg.key); | ||
if (fn) { | ||
fn(...msg.args); | ||
} | ||
hub._callFunc(msg); | ||
break; | ||
@@ -86,0 +83,0 @@ |
@@ -21,2 +21,3 @@ const cluster = require('cluster'); | ||
this._funcs = new Map(); | ||
this._funcsHistory = new Set(); | ||
this._maxFuncs = 100; | ||
@@ -144,5 +145,2 @@ | ||
funcs.push({ i, key: this._keyFunc(this._funcs, arg) }); | ||
if (this._funcs.size > this._maxFuncs) { | ||
this._funcs.delete(this._funcs.keys().next().value); | ||
} | ||
} | ||
@@ -154,2 +152,21 @@ } | ||
/** | ||
* Calls a function that was called by another process. | ||
* | ||
* @param {Object} msg | ||
*/ | ||
_callFunc(msg) { | ||
const fn = this._funcs.get(msg.key); | ||
if (fn) { | ||
fn(...msg.args); | ||
this._funcsHistory.delete(msg.key); | ||
this._funcsHistory.add(msg.key); | ||
if (this._funcsHistory.size > this._maxFuncs) { | ||
const key = this._funcsHistory.keys().next().value; | ||
this._funcs.delete(key); | ||
this._funcsHistory.delete(key); | ||
} | ||
} | ||
} | ||
/** | ||
* Emits event to all workers and the master in the hub. | ||
@@ -280,7 +297,8 @@ * | ||
this.removeAllListeners(); | ||
this._funcs = new Map(); | ||
this._funcs.clear(); | ||
this._funcsHistory.clear(); | ||
if (isMaster) { | ||
this._db.die(); | ||
} else { | ||
this._callbacks = new Map(); | ||
this._callbacks.clear(); | ||
} | ||
@@ -287,0 +305,0 @@ } |
@@ -37,6 +37,3 @@ const commands = require('./globals').commands; | ||
case commands.FN: | ||
fn = hub._funcs.get(msg.key); | ||
if (fn) { | ||
fn(...msg.args); | ||
} | ||
hub._callFunc(msg); | ||
break; | ||
@@ -43,0 +40,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"repository": { | ||
@@ -14,0 +14,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19976
530
0