diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-05-19 14:05:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-19 14:05:57 +0200 |
commit | 5ffcbcfcc84b9cce891acb165bc7644ec4a0fe64 (patch) | |
tree | 082a7f4e4d585f97f6a73d620abdd5af6f734f7a | |
parent | 4e1ca1d1787f25ab9f0a72ccf9d8028f70b3a7ed (diff) |
feat: make Child.kill argument optional (#14669)
-rw-r--r-- | cli/dts/lib.deno.unstable.d.ts | 4 | ||||
-rw-r--r-- | cli/tests/unit/spawn_test.ts | 23 | ||||
-rw-r--r-- | runtime/js/40_spawn.js | 2 |
3 files changed, 26 insertions, 3 deletions
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index bb93eac8d..e21c2afce 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -1060,8 +1060,8 @@ declare namespace Deno { /** Waits for the child to exit completely, returning all its output and status. */ output(): Promise<SpawnOutput<T>>; - /** Kills the process with given Signal. */ - kill(signo: Signal): void; + /** Kills the process with given Signal. Defaults to SIGTERM. */ + kill(signo?: Signal): void; } /** diff --git a/cli/tests/unit/spawn_test.ts b/cli/tests/unit/spawn_test.ts index 40224dfb4..de47b8757 100644 --- a/cli/tests/unit/spawn_test.ts +++ b/cli/tests/unit/spawn_test.ts @@ -250,6 +250,29 @@ Deno.test( Deno.test( { permissions: { run: true, read: true } }, + async function spawnKillOptional() { + const child = Deno.spawnChild(Deno.execPath(), { + args: ["eval", "setTimeout(() => {}, 10000)"], + stdout: "null", + stderr: "null", + }); + + child.kill(); + const status = await child.status; + + assertEquals(status.success, false); + if (Deno.build.os === "windows") { + assertEquals(status.code, 1); + assertEquals(status.signal, null); + } else { + assertEquals(status.code, 143); + assertEquals(status.signal, "SIGTERM"); + } + }, +); + +Deno.test( + { permissions: { run: true, read: true } }, async function spawnAbort() { const ac = new AbortController(); const child = Deno.spawnChild(Deno.execPath(), { diff --git a/runtime/js/40_spawn.js b/runtime/js/40_spawn.js index 77236ee2b..7a2f06b6a 100644 --- a/runtime/js/40_spawn.js +++ b/runtime/js/40_spawn.js @@ -165,7 +165,7 @@ }; } - kill(signo) { + kill(signo = "SIGTERM") { if (this.#rid === null) { throw new TypeError("Child process has already terminated."); } |