Skip to content

Commit 94e637b

Browse files
committed
add closed getter
1 parent f77e244 commit 94e637b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/internal/child_process.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const kChannelHandle = Symbol('kChannelHandle');
8787
const kIsUsedAsStdio = Symbol('kIsUsedAsStdio');
8888
const kPendingMessages = Symbol('kPendingMessages');
8989
const kKillSignal = Symbol('kKillSignal');
90-
const kWasClosed = Symbol('kWasClosed');
9190

9291
// This object contain function to convert TCP objects to native handle objects
9392
// and back again.
@@ -266,7 +265,6 @@ function ChildProcess(killSignal) {
266265
this.exitCode = null;
267266
this.killed = false;
268267
this.spawnfile = null;
269-
this[kWasClosed] = false;
270268
this[kKillSignal] = killSignal;
271269

272270
this._handle = new Process();
@@ -318,6 +316,15 @@ function ChildProcess(killSignal) {
318316
ObjectSetPrototypeOf(ChildProcess.prototype, EventEmitter.prototype);
319317
ObjectSetPrototypeOf(ChildProcess, EventEmitter);
320318

319+
ObjectDefineProperty(ChildProcess.prototype, 'closed', {
320+
__proto__: null,
321+
get() {
322+
return this._closesGot === this._closesNeeded;
323+
},
324+
configurable: true,
325+
enumerable: false,
326+
});
327+
321328

322329
function flushStdio(subprocess) {
323330
const stdio = subprocess.stdio;
@@ -523,7 +530,7 @@ ChildProcess.prototype.kill = function(sig) {
523530
};
524531

525532
ChildProcess.prototype[SymbolAsyncDispose] = async function() {
526-
if (!this[kWasClosed]) {
533+
if (!this.closed) {
527534
const promise = EventEmitter.once(this, 'close');
528535
const ret = this.kill(this[kKillSignal]);
529536
assert(ret, 'unexpected kill failure');
@@ -1109,9 +1116,7 @@ function getSocketList(type, worker, key) {
11091116

11101117
function maybeClose(subprocess) {
11111118
subprocess._closesGot++;
1112-
1113-
if (subprocess._closesGot === subprocess._closesNeeded) {
1114-
subprocess[kWasClosed] = true;
1119+
if (subprocess.closed) {
11151120
subprocess.emit('close', subprocess.exitCode, subprocess.signalCode);
11161121
}
11171122
}

0 commit comments

Comments
 (0)