summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2014-01-04 02:07:44 -0800
committerTrevor Norris <trev.norris@gmail.com>2014-01-04 03:04:19 -0800
commit3f2cfe1762856ac1a6cf5872de33d5f121937b8f (patch)
tree3dc9711f02f4aab879e2be1deb030f174b291535
parent1def590db5a4a90ff53239c2f8ae844bdf9b3547 (diff)
downloadnode-3f2cfe1762856ac1a6cf5872de33d5f121937b8f.tar.gz
child_process: emit close in proper phase of eloop
-rw-r--r--lib/child_process.js27
1 files changed, 9 insertions, 18 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index bcbd08d6c..6c63d327b 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -355,6 +355,8 @@ function setupChannel(target, channel) {
target.disconnect();
channel.onread = nop;
channel.close();
+ // TODO(trevnorris): Don't close this until after the close callback
+ // has fired.
maybeClose(target);
}
};
@@ -853,26 +855,15 @@ function ChildProcess() {
self.stdin.destroy();
}
- self._handle.close();
- self._handle = null;
-
- if (exitCode < 0) {
- self.emit('error', err);
- } else {
- self.emit('exit', self.exitCode, self.signalCode);
- }
-
- // if any of the stdio streams have not been touched,
- // then pull all the data through so that it can get the
- // eof and emit a 'close' event.
- // Do it on nextTick so that the user has one last chance
- // to consume the output, if for example they only want to
- // start reading the data once the process exits.
- process.nextTick(function() {
+ self._handle.close(function() {
+ if (exitCode < 0)
+ self.emit('error', err);
+ else
+ self.emit('exit', self.exitCode, self.signalCode);
flushStdio(self);
+ maybeClose(self);
});
-
- maybeClose(self);
+ self._handle = null;
};
}
util.inherits(ChildProcess, EventEmitter);