src/master.js
function handleWorkerPayload (payload) {
  // Parse and validate received payload.
  if ((payload = utils.parsePayload(payload)) === null) return

  // If the master is configured to echo events to its own master, the event
  // emitted by the worker should be echoed to the master.
  if (this.__echoEvents === true) {
    const echoPayload = JSON.parse(JSON.stringify(payload))
    // Update PID as if the payload is originating from this process, the master
    // is in. If this is not done, the master of this process, will resend the
    // payload since the PID is different.
    echoPayload[fields.pid] = process.pid
    process.send(echoPayload)
  }

  // Unmarshal args.
  payload[fields.args] = marshaller.unmarshal(payload[fields.args])

  // Notify instance listeners.
  events.prototype.emit.call(this, payload[fields.event],
    ...payload[fields.args])

  // Notify all workers except the worker who emitted the event.
  sendPayload.call(this, payload)
}
function handleWorkerPayload (payload) {
  // Parse and validate received payload.
  if ((payload = utils.parsePayload(payload)) === null) return

  // If the master is configured to echo events to its own master, the event
  // emitted by the worker should be echoed to the master.
  if (this.__echoEvents === true) {
    const echoPayload = JSON.parse(JSON.stringify(payload))
    // Update PID as if the payload is originating from this process, the master
    // is in. If this is not done, the master of this process, will resend the
    // payload since the PID is different.
    echoPayload[fields.pid] = process.pid
    process.send(echoPayload)
  }

  // Unmarshal args.
  payload[fields.args] = marshaller.unmarshal(payload[fields.args])

  // Notify instance listeners.
  events.prototype.emit.call(this, payload[fields.event],
    ...payload[fields.args])

  // Notify all workers except the worker who emitted the event.
  sendPayload.call(this, payload)
}
function handleWorkerPayload ( payload ) { // Parse and validate received payload. if ( ( payload = utils . parsePayload ( payload ) ) === null ) return // If the master is configured to echo events to its own master, the event // emitted by the worker should be echoed to the master. if ( this . __echoEvents === true ) { const echoPayload = JSON . parse ( JSON . stringify ( payload ) ) // Update PID as if the payload is originating from this process, the master // is in. If this is not done, the master of this process, will resend the // payload since the PID is different. echoPayload [ fields . pid ] = process . pid process . send ( echoPayload ) } // Unmarshal args. payload [ fields . args ] = marshaller . unmarshal ( payload [ fields . args ] ) // Notify instance listeners. events . prototype . emit . call ( this , payload [ fields . event ] , ... payload [ fields . args ] ) // Notify all workers except the worker who emitted the event. sendPayload . call ( this , payload ) }
handleWorkerPayload handles the payload received by a worker. If payload is
valid it is echoed back to all workers except the worker that it was received
from.
@param  {String} payload Payload received from a worker.
handleWorkerPayload handles the payload received by a worker . If payload is valid it is echoed back to all workers except the worker that it was received from .