You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
I know this use internal API, but the cluster 2.0 module ( see: #2038 ) use this.
Here is a simpel master. It will fork a new "worker" just using child_process and when it gets a message from the worker it will disconnect it. The master should now die since there can't happen anything more, but it dose not!
varchild=require('child_process');varutil=require('util');varworker=child.fork('worker.js');worker.once('message',function(){console.log('now disconnecing');worker._channel.close();//Lets se the contentconsole.log(util.inspect(worker._channel));//try sending a message to the workertry{worker.send('say hi');}catch(e){console.log('got an error, because the channel is closed :');console.log(e);}});
And this is the worker. It will create a simpel http server just to keep it alive.
varhttp=require('http');varutil=require('util');//Keep the worker alivehttp.createServer(function(req,res){res.writeHead(200,{'Content-Type': 'text/plain'});res.write('PID: '+process.pid+"\n");//Lets see process._channelres.write(util.inspect(process._channel));res.end();}).listen(8000,"127.0.0.1",function(){process.send('hey master, please disconnect me');});
Also when the master disconnect its worker the worker._channel is not null and the worker._channel.destroyed is false. However in in the worker the worker._channel property is null.