mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
child_process: support Symbol.dispose
PR-URL: https://github.com/nodejs/node/pull/48551 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
1 parent
c47ea21685
commit
773fde29a9
3 files changed
+42
No files matched your search
@@ -1402,6 +1402,16 @@ setTimeout(() => {
|
||||
}, 2000);
|
||||
```
|
||||
|
||||
### `subprocess[Symbol.dispose]()`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
> Stability: 1 - Experimental
|
||||
|
||||
Calls [`subprocess.kill()`][] with `'SIGTERM'`.
|
||||
|
||||
### `subprocess.killed`
|
||||
|
||||
<!-- YAML
|
||||
|
||||
@@ -12,6 +12,7 @@ const {
|
||||
ReflectApply,
|
||||
StringPrototypeSlice,
|
||||
Symbol,
|
||||
SymbolDispose,
|
||||
Uint8Array,
|
||||
} = primordials;
|
||||
|
||||
@@ -516,6 +517,12 @@ ChildProcess.prototype.kill = function(sig) {
|
||||
return false;
|
||||
};
|
||||
|
||||
ChildProcess.prototype[SymbolDispose] = function() {
|
||||
if (!this.killed) {
|
||||
this.kill();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ChildProcess.prototype.ref = function() {
|
||||
if (this._handle) this._handle.ref();
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const spawn = require('child_process').spawn;
|
||||
const cat = spawn(common.isWindows ? 'cmd' : 'cat');
|
||||
|
||||
cat.stdout.on('end', common.mustCall());
|
||||
cat.stderr.on('data', common.mustNotCall());
|
||||
cat.stderr.on('end', common.mustCall());
|
||||
|
||||
cat.on('exit', common.mustCall((code, signal) => {
|
||||
assert.strictEqual(code, null);
|
||||
assert.strictEqual(signal, 'SIGTERM');
|
||||
assert.strictEqual(cat.signalCode, 'SIGTERM');
|
||||
}));
|
||||
cat.on('exit', common.mustCall((code, signal) => {
|
||||
assert.strictEqual(code, null);
|
||||
assert.strictEqual(signal, 'SIGTERM');
|
||||
assert.strictEqual(cat.signalCode, 'SIGTERM');
|
||||
}));
|
||||
|
||||
assert.strictEqual(cat.signalCode, null);
|
||||
assert.strictEqual(cat.killed, false);
|
||||
cat[Symbol.dispose]();
|
||||
assert.strictEqual(cat.killed, true);
|
||||
Reference in new issue
Block a user