cluster: emit worker as first 'message' event arg by bnoordhuis · Pull Request #5361 · nodejs/node (original) (raw)

bnoordhuis

@bnoordhuis bnoordhuis added cluster

Issues and PRs related to the cluster subsystem.

semver-major

PRs that contain breaking changes and should be released in the next major version.

labels

Feb 22, 2016

thefourtheye

cluster.emit('message', message, handle)
);
worker.on('message', function(message, handle) {
cluster.emit('message', this, message, handle);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I am missing something. When the message event is emitted by cluster, the this will be cluster, not the worker object, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event is emitted on the worker object, the listener simply re-emits it on the cluster object (hence why it was changed from an arrow function to a normal function - no lexical this.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better if we say worker instead of this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it if you think it's clearer. The way it's written now saves a few bytes of memory and reduces GC strain infinitesimally (one fewer closure context variable to traverse.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even I was thinking about the closure variable access. But then every time someone goes through the code, they would have to spend time on this to really understand this. Maybe that's just me.

@thefourtheye

1 similar comment

@cjihrig

ofrobots

Emitted when any worker receives a message.
See [child_process event: 'message'][].
Until Node.js v6.0, this event emitted only the message and the handle,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this wording ('Until') makes it ambiguous what the behaviour of v6.0 is. Use 'Before Node.js v6.0' perhaps?

@bnoordhuis

It's documented as such but didn't actually behave that way.

Bug introduced in commit 66fc8ca ("cluster: emit 'message' event on cluster master"), which is the commit that introduced the event.

Fixes: nodejs#5126 PR-URL: nodejs#5361 Reviewed-By: Ali Ijaz Sheikh ofrobots@google.com Reviewed-By: Colin Ihrig cjihrig@gmail.com Reviewed-By: Sakthipriyan Vairamani thechargingvolcano@gmail.com

@bnoordhuis

Landed in 66f4586 with Ali's feedback incorporated. Thanks for the review everyone.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.