Skip to content

Commit

Permalink
Remove abort method.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Aug 5, 2023
1 parent bb4851e commit 8496ff7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
6 changes: 3 additions & 3 deletions mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,15 @@ Deno.test("abort", async () => {
await assertRejects(
async () => {
const child = command.spawn();
child.abort();
child.kill();
await child;
},
Error,
"Aborted with exit code: 124",
);

const child = command.noThrow().spawn();
child.abort();
child.kill();
const result = await child;
assertEquals(result.code, 124);
});
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,12 @@ export class CommandChild extends Promise<CommandResult> {
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);
}

Expand Down

0 comments on commit 8496ff7

Please sign in to comment.