Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 611db8d

Browse filesBrowse files
MoLowruyadorno
authored andcommitted
child_process: support Symbol.dispose
PR-URL: #48551 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 51863b8 commit 611db8d
Copy full SHA for 611db8d

File tree

Expand file treeCollapse file tree

3 files changed

+42
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+42
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/child_process.md‎

Copy file name to clipboardExpand all lines: doc/api/child_process.md
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,16 @@ setTimeout(() => {
14021402
}, 2000);
14031403
```
14041404

1405+
### `subprocess[Symbol.dispose]()`
1406+
1407+
<!-- YAML
1408+
added: REPLACEME
1409+
-->
1410+
1411+
> Stability: 1 - Experimental
1412+
1413+
Calls [`subprocess.kill()`][] with `'SIGTERM'`.
1414+
14051415
### `subprocess.killed`
14061416

14071417
<!-- YAML
Collapse file

‎lib/internal/child_process.js‎

Copy file name to clipboardExpand all lines: lib/internal/child_process.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
ReflectApply,
1313
StringPrototypeSlice,
1414
Symbol,
15+
SymbolDispose,
1516
Uint8Array,
1617
} = primordials;
1718

@@ -509,6 +510,12 @@ ChildProcess.prototype.kill = function(sig) {
509510
return false;
510511
};
511512

513+
ChildProcess.prototype[SymbolDispose] = function() {
514+
if (!this.killed) {
515+
this.kill();
516+
}
517+
};
518+
512519

513520
ChildProcess.prototype.ref = function() {
514521
if (this._handle) this._handle.ref();
Collapse file
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const spawn = require('child_process').spawn;
5+
const cat = spawn(common.isWindows ? 'cmd' : 'cat');
6+
7+
cat.stdout.on('end', common.mustCall());
8+
cat.stderr.on('data', common.mustNotCall());
9+
cat.stderr.on('end', common.mustCall());
10+
11+
cat.on('exit', common.mustCall((code, signal) => {
12+
assert.strictEqual(code, null);
13+
assert.strictEqual(signal, 'SIGTERM');
14+
assert.strictEqual(cat.signalCode, 'SIGTERM');
15+
}));
16+
cat.on('exit', common.mustCall((code, signal) => {
17+
assert.strictEqual(code, null);
18+
assert.strictEqual(signal, 'SIGTERM');
19+
assert.strictEqual(cat.signalCode, 'SIGTERM');
20+
}));
21+
22+
assert.strictEqual(cat.signalCode, null);
23+
assert.strictEqual(cat.killed, false);
24+
cat[Symbol.dispose]();
25+
assert.strictEqual(cat.killed, true);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.