From 8496ff7429f82b8bd40be972f981a33a1f909023 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 5 Aug 2023 16:20:49 -0400 Subject: [PATCH] Remove abort method. --- README.md | 4 ++-- mod.test.ts | 6 +++--- src/command.ts | 11 ++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0fc44d7..dce7a7a 100644 --- a/README.md +++ b/README.md @@ -239,9 +239,9 @@ Instead of awaiting the template literal, you can get a command child by calling ```ts const child = $`echo 1 && sleep 100 && echo 2`.spawn(); -// abort the child after 1s +// kill the child after 1s await $.sleep("1s"); -child.abort(); +child.kill(); // or provide other signals like "SIGKILL". It uses "SIGTERM" by default await child; // Error: Aborted with exit code: 124 ``` diff --git a/mod.test.ts b/mod.test.ts index 6319611..a2f8c3d 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -696,7 +696,7 @@ Deno.test("abort", async () => { await assertRejects( async () => { const child = command.spawn(); - child.abort(); + child.kill(); await child; }, Error, @@ -704,7 +704,7 @@ Deno.test("abort", async () => { ); const child = command.noThrow().spawn(); - child.abort(); + child.kill(); const result = await child; assertEquals(result.code, 124); }); @@ -895,7 +895,7 @@ Deno.test("streaming api stdin not used in provided command", async () => { .stdin(stdout) .text(); assertEquals(text, "1"); - child.abort(); + child.kill(); await assertRejects( async () => { await child; diff --git a/src/command.ts b/src/command.ts index d1f9c4c..86980f1 100644 --- a/src/command.ts +++ b/src/command.ts @@ -478,15 +478,12 @@ export class CommandChild extends Promise { this.#commandSignalController = options.commandSignalController; } - /** Cancels the executing command, sending any spawned child process a SIGTERM if able. */ - abort(): void { - this.#commandSignalController?.abort(); - } - /** Send a signal to the executing command's child process. Note that SIGTERM, - * SIGKILL, SIGABRT, SIGQUIT, SIGINT, or SIGSTOP will also abort the command. + * SIGKILL, SIGABRT, SIGQUIT, SIGINT, or SIGSTOP will cause the entire command + * to be considered "aborted" and will return a 124 exit code, while other signals + * will just be forwarded to the command. */ - kill(signal: Deno.Signal): void { + kill(signal: Deno.Signal = "SIGTERM"): void { this.#commandSignalController?.sendSignal(signal); }