Skip to content

Commit

Permalink
Use p-event in ClusterProcess, WorkerPool and Worker
Browse files Browse the repository at this point in the history
  • Loading branch information
mcheshkov committed Jul 18, 2018
1 parent a2f24ee commit b2622b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/cluster_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const cluster = require('cluster'),
LusterClusterProcessError = require('./errors').LusterClusterProcessError,
LusterConfigurationError = require('./errors').LusterConfigurationError;

const pEvent = require('p-event');

/**
* @param {Object} context
* @param {String} propName
Expand Down Expand Up @@ -59,9 +61,7 @@ class ClusterProcess extends EventEmitterEx {
* @type Promise<void>
* @private
* */
this._initPromise = new Promise(resolve => {
this.once('initialized', resolve);
});
this._initPromise = pEvent(this, 'initialized');

/**
* @type {Configuration}
Expand Down
4 changes: 1 addition & 3 deletions lib/worker-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class WorkerPool extends EventEmitterEx {
*/
this._restartQueue = new RestartQueue(key);

this._runningPromise = new Promise(resolve => {
this.once('running', resolve);
});
this._runningPromise = pEvent(this, 'running');

this.dead = false;

Expand Down
8 changes: 3 additions & 5 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const cluster = require('cluster'),
ClusterProcess = require('./cluster_process'),
LusterWorkerError = require('./errors').LusterWorkerError;

const pEvent = require('p-event');

const wid = parseInt(process.env.LUSTER_WID, 10);

/**
Expand All @@ -19,11 +21,7 @@ class Worker extends ClusterProcess {

const broadcastEvent = this._broadcastEvent;

this._foreignPropertiesReceivedPromise = new Promise(resolve => {
this.once('foreign properties received', () => {
resolve();
});
});
this._foreignPropertiesReceivedPromise = pEvent(this, 'foreign properties received');

this.on('configured', broadcastEvent.bind(this, 'configured'));
this.on('extension loaded', broadcastEvent.bind(this, 'extension loaded'));
Expand Down

0 comments on commit b2622b6

Please sign in to comment.