mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
feat: make Child.kill argument optional (#14669)
This commit is contained in:
parent
4e1ca1d178
commit
5ffcbcfcc8
3 changed files with 26 additions and 3 deletions
4
cli/dts/lib.deno.unstable.d.ts
vendored
4
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -1060,8 +1060,8 @@ declare namespace Deno {
|
||||||
|
|
||||||
/** Waits for the child to exit completely, returning all its output and status. */
|
/** Waits for the child to exit completely, returning all its output and status. */
|
||||||
output(): Promise<SpawnOutput<T>>;
|
output(): Promise<SpawnOutput<T>>;
|
||||||
/** Kills the process with given Signal. */
|
/** Kills the process with given Signal. Defaults to SIGTERM. */
|
||||||
kill(signo: Signal): void;
|
kill(signo?: Signal): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -248,6 +248,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(
|
Deno.test(
|
||||||
{ permissions: { run: true, read: true } },
|
{ permissions: { run: true, read: true } },
|
||||||
async function spawnAbort() {
|
async function spawnAbort() {
|
||||||
|
|
|
@ -165,7 +165,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
kill(signo) {
|
kill(signo = "SIGTERM") {
|
||||||
if (this.#rid === null) {
|
if (this.#rid === null) {
|
||||||
throw new TypeError("Child process has already terminated.");
|
throw new TypeError("Child process has already terminated.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue