File tree 3 files changed +42
-0
lines changed
3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1402,6 +1402,16 @@ setTimeout(() => {
1402
1402
}, 2000 );
1403
1403
```
1404
1404
1405
+ ### ` subprocess[Symbol.dispose]() `
1406
+
1407
+ <!-- YAML
1408
+ added: REPLACEME
1409
+ -->
1410
+
1411
+ > Stability: 1 - Experimental
1412
+
1413
+ Calls [ ` subprocess.kill() ` ] [ ] with ` 'SIGTERM' ` .
1414
+
1405
1415
### ` subprocess.killed `
1406
1416
1407
1417
<!-- YAML
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ const {
12
12
ReflectApply,
13
13
StringPrototypeSlice,
14
14
Symbol,
15
+ SymbolDispose,
15
16
Uint8Array,
16
17
} = primordials ;
17
18
@@ -516,6 +517,12 @@ ChildProcess.prototype.kill = function(sig) {
516
517
return false ;
517
518
} ;
518
519
520
+ ChildProcess . prototype [ SymbolDispose ] = function ( ) {
521
+ if ( ! this . killed ) {
522
+ this . kill ( ) ;
523
+ }
524
+ } ;
525
+
519
526
520
527
ChildProcess . prototype . ref = function ( ) {
521
528
if ( this . _handle ) this . _handle . ref ( ) ;
Original file line number Diff line number Diff line change
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 ) ;
You can’t perform that action at this time.
0 commit comments