-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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.on('message') not return worker #5764
Comments
@Hamper Try: |
It does looks like order of the arguments as told by the docs is incorrect though. |
'use strict'
const cluster = require('cluster')
if (cluster.isMaster) {
cluster.on('message', (msg, wrk) => console.log(`msg=${msg}, wrk=${wrk}`))
cluster.fork()
} else {
cluster.worker.send('test')
process.send('test2')
} result:
|
The documentation agrees with master, but not 5.x/4.x. |
a doc fix PR should be made targeting both edit: this will need to be 2 pr's |
Looks like the |
@nodejs/documentation |
Hi, |
In the top of your else statement try this |
Hi @lordKnighton , var cluster = require('cluster');
if(cluster.isMaster) {
cluster.on('message', function(worker, message) {
console.log(`Worker ${worker.id} said "${message}"`);
console.log(`Worker ${worker} said "${message}"`);
}
cluster.fork();
}
else {
process.send('Hello World!!!!');
} The result in console is:
|
I've just tested the same code within Node.js v6.1.0 and it works like a charm. |
This commit corrects the cluster message event signature. Fixes: nodejs#5764
A fix for v4.x-staging is at #7297. I'm inclined to not fix v5.x, as it is EOL in a couple weeks. |
Closed in 47f82cd. |
In documentation:
but real use is:
The text was updated successfully, but these errors were encountered: