Comparing version 2.0.2 to 2.1.0
@@ -51,3 +51,4 @@ /** | ||
broadcastMasterEvent: 'core.worker.broadcastMasterEvent', | ||
applyForeignProperties: 'core.worker.applyForeignProperties' | ||
applyForeignProperties: 'core.worker.applyForeignProperties', | ||
suspend: 'core.worker.suspend' | ||
}, | ||
@@ -54,0 +55,0 @@ master: { |
@@ -424,3 +424,9 @@ const cluster = require('cluster'), | ||
if (this.isRunning()) { | ||
this._worker.disconnect(); | ||
this.remoteCallWithCallback({ | ||
command: RPC.fns.worker.suspend, | ||
callback: () => { | ||
this._worker.disconnect(); | ||
} | ||
}); | ||
this._scheduleForceStop(); | ||
@@ -427,0 +433,0 @@ } |
@@ -37,2 +37,6 @@ const cluster = require('cluster'), | ||
this.registerRemoteCommand(RPC.fns.worker.broadcastMasterEvent, this.broadcastMasterEvent.bind(this)); | ||
this._suspendFunctions = []; | ||
this.registerRemoteCommandWithCallback(RPC.fns.worker.suspend, this._suspend.bind(this)); | ||
this._suspendPromise = null; | ||
} | ||
@@ -165,2 +169,33 @@ | ||
} | ||
/** | ||
* @callback SuspendFunction | ||
* @returns void|Promise<void> | ||
*/ | ||
/** | ||
* This adds new function that will be called before stopping worker. | ||
* Worker will wait for returned promise to resolve and then report to master it suspended successfully. | ||
* Rejects will emit 'error' event, no report to master will happen. | ||
* All suspend functions are called simultaneously. | ||
* Suspend function will not be called more than once. | ||
* @param {SuspendFunction} func | ||
* @public | ||
*/ | ||
registerSuspendFunction(func) { | ||
this._suspendFunctions.push(func); | ||
} | ||
_suspend(callback) { | ||
if (!this._suspendPromise) { | ||
this._suspendPromise = Promise.all(this._suspendFunctions.map(func => func())); | ||
} | ||
this._suspendPromise.then( | ||
callback, | ||
error => { | ||
this.emit('error', error); | ||
} | ||
); | ||
} | ||
} | ||
@@ -167,0 +202,0 @@ |
{ | ||
"name": "luster", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Node.js cluster wrapper", | ||
@@ -47,2 +47,3 @@ "main": "./lib/luster.js", | ||
"mocha": "^3.1.2", | ||
"p-event": "^4.1.0", | ||
"sinon": "^1.17.6", | ||
@@ -49,0 +50,0 @@ "sinon-chai": "^2.8.0" |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
87481
2218
0
8