From d1fa59fbb7012f8edd37a37cd668b747664c018d Mon Sep 17 00:00:00 2001 From: Brian White Date: Sun, 4 Jun 2017 20:12:48 -0400 Subject: [PATCH] child_process: simplify send() result handling PR-URL: https://github.com/nodejs/node/pull/13459 Reviewed-By: Refael Ackermann Reviewed-By: Ben Noordhuis --- lib/internal/child_process.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index abd4b16d120dc3..68dd1145d32630 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -645,16 +645,15 @@ function setupChannel(target, channel) { obj.postSend(handle, options, target); } - req.oncomplete = function() { - if (this.async === true) + if (req.async) { + req.oncomplete = function() { control.unref(); - if (typeof callback === 'function') - callback(null); - }; - if (req.async === true) { + if (typeof callback === 'function') + callback(null); + }; control.ref(); - } else { - process.nextTick(function() { req.oncomplete(); }); + } else if (typeof callback === 'function') { + process.nextTick(callback, null); } } else { // Cleanup handle on error