child_process: do not disconnect on exit emit

When using isolate the .fork would break because it had
no .disconnect method. This remove the exit handler there
would call .disconnect since it was not required.
It also change .disconnect to throw if the channel is closed,
this was not possible before because .disconnect would be called
twice.
This commit is contained in:
Andreas Madsen 2012-01-31 17:14:42 +01:00 коммит произвёл isaacs
Родитель 03c4aa6aef
Коммит 33b7fc250f
2 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -158,7 +158,9 @@ function setupChannel(target, channel) {
target.connected = true;
target.disconnect = function() {
if (!this.connected) return;
if (!this.connected) {
this.emit('error', new Error('IPC channel is already disconnected'));
}
// do not allow messages to be written
this.connected = false;
@ -231,9 +233,6 @@ exports.fork = function(modulePath /*, args, options*/) {
if (!options.thread) setupChannel(child, options.stdinStream);
// Disconnect when the child process exits.
child.once('exit', child.disconnect.bind(child));
return child;
};

Просмотреть файл

@ -85,6 +85,7 @@ if (process.argv[2] === 'child') {
// ready to be disconnected
if (data === 'ready') {
child.disconnect();
assert.throws(child.disconnect.bind(child), Error);
return;
}