summaryrefslogtreecommitdiff
path: root/runtime/js/40_spawn.js
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2022-05-11 07:59:39 +0200
committerGitHub <noreply@github.com>2022-05-11 07:59:39 +0200
commitb67f874b3fb172168997be410b1d5e3c3109c763 (patch)
treeab24a5ffe1fd7bb54a43e9a6b3e4b13fa153cfe7 /runtime/js/40_spawn.js
parente3f4b02f48c1e1b1e70cb9237126b9bc5d9720e3 (diff)
feat(runtime/spawn): add `AbortSignal` support (#14538)
Diffstat (limited to 'runtime/js/40_spawn.js')
-rw-r--r--runtime/js/40_spawn.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/runtime/js/40_spawn.js b/runtime/js/40_spawn.js
index 3b609be8b..4f680c7e1 100644
--- a/runtime/js/40_spawn.js
+++ b/runtime/js/40_spawn.js
@@ -5,6 +5,7 @@
const core = window.Deno.core;
const { pathFromURL } = window.__bootstrap.util;
const { illegalConstructorKey } = window.__bootstrap.webUtil;
+ const { add, remove } = window.__bootstrap.abortSignal;
const {
ArrayPrototypeMap,
ObjectEntries,
@@ -26,6 +27,7 @@
stdin = "null",
stdout = "piped",
stderr = "piped",
+ signal = undefined,
} = {}) {
const child = core.opSync("op_spawn_child", {
cmd: pathFromURL(command),
@@ -39,7 +41,10 @@
stdout,
stderr,
});
- return new Child(illegalConstructorKey, child);
+ return new Child(illegalConstructorKey, {
+ ...child,
+ signal,
+ });
}
async function collectOutput(readableStream) {
@@ -91,6 +96,7 @@
}
constructor(key = null, {
+ signal,
rid,
pid,
stdinRid,
@@ -119,8 +125,12 @@
this.#stderr = readableStreamForRid(stderrRid);
}
+ const onAbort = () => this.kill("SIGTERM");
+ signal?.[add](onAbort);
+
this.#status = core.opAsync("op_spawn_wait", this.#rid).then((res) => {
this.#rid = null;
+ signal?.[remove](onAbort);
return res;
});
}