Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: refine worker.destroy function #6502

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,13 @@ function workerInit() {

Worker.prototype.destroy = function() {
this.exitedAfterDisconnect = true;
if (!this.isConnected()) process.exit(0);
var exit = process.exit.bind(null, 0);
send({ act: 'exitedAfterDisconnect' }, () => process.disconnect());
process.once('disconnect', exit);
var code = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you drop this altogether or at least make it const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjihrig I choose to use your suggestion 1 because of the consistence with other functions in this module.

if (!this.isConnected()) {
process.exit(code);
} else {
send({ act: 'exitedAfterDisconnect' }, () => process.disconnect());
process.once('disconnect', () => process.exit(code));
}
Copy link
Member

Choose a reason for hiding this comment

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

Why not eliminate the bind() altogether?

if (!this.isConnected()) {
  process.exit(0);
} else {
  send({ act: 'exitedAfterDisconnect' }, () => process.disconnect());
  process.once('disconnect', () => process.exit(0));
}

};

function send(message, cb) {
Expand Down