| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| 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 | ||
@@ -509,6 +510,12 @@ ChildProcess.prototype.kill = function(sig) { | |||
| 509 | 510 | return false; | |
| 510 | 511 | }; | |
| 511 | 512 | ||
| 513 | + ChildProcess.prototype[SymbolDispose] = function() { | ||
| 514 | + if (!this.killed) { | ||
| 515 | + this.kill(); | ||
| 516 | + } | ||
| 517 | + }; | ||
| 518 | + | ||
| 512 | 519 | ||
| 513 | 520 | ChildProcess.prototype.ref = function() { | |
| 514 | 521 | if (this._handle) this._handle.ref(); | |
| Original file line number | Diff line number | Diff 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); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments