summaryrefslogtreecommitdiff
path: root/runtime/js/40_process.js
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2023-11-01 20:26:12 +0100
committerGitHub <noreply@github.com>2023-11-01 20:26:12 +0100
commitd42f1543121e7245789a96a485d1ef7645cb5fba (patch)
treed57a10ac527fe5b6796a3a8866af95f0f1a5d7bd /runtime/js/40_process.js
parent1d19b1011bd7df50598f5981408c2d78c35b76d2 (diff)
feat: disposable Deno resources (#20845)
This commit implements Symbol.dispose and Symbol.asyncDispose for the relevant resources. Closes #20839 --------- Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/js/40_process.js')
-rw-r--r--runtime/js/40_process.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/runtime/js/40_process.js b/runtime/js/40_process.js
index 664a4b303..4ddc4a02a 100644
--- a/runtime/js/40_process.js
+++ b/runtime/js/40_process.js
@@ -18,7 +18,11 @@ const {
} = primordials;
import { FsFile } from "ext:deno_fs/30_fs.js";
import { readAll } from "ext:deno_io/12_io.js";
-import { assert, pathFromURL } from "ext:deno_web/00_infra.js";
+import {
+ assert,
+ pathFromURL,
+ SymbolAsyncDispose,
+} from "ext:deno_web/00_infra.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
import {
readableStreamCollectIntoUint8Array,
@@ -201,7 +205,6 @@ class ChildProcess {
#rid;
#waitPromiseId;
#waitComplete = false;
- #unrefed = false;
#pid;
get pid() {
@@ -216,7 +219,6 @@ class ChildProcess {
return this.#stdin;
}
- #stdoutRid;
#stdout = null;
get stdout() {
if (this.#stdout == null) {
@@ -225,7 +227,6 @@ class ChildProcess {
return this.#stdout;
}
- #stderrRid;
#stderr = null;
get stderr() {
if (this.#stderr == null) {
@@ -254,12 +255,10 @@ class ChildProcess {
}
if (stdoutRid !== null) {
- this.#stdoutRid = stdoutRid;
this.#stdout = readableStreamForRidUnrefable(stdoutRid);
}
if (stderrRid !== null) {
- this.#stderrRid = stderrRid;
this.#stderr = readableStreamForRidUnrefable(stderrRid);
}
@@ -324,15 +323,22 @@ class ChildProcess {
ops.op_spawn_kill(this.#rid, signo);
}
+ async [SymbolAsyncDispose]() {
+ try {
+ ops.op_spawn_kill(this.#rid, "SIGTERM");
+ } catch {
+ // ignore errors from killing the process (such as ESRCH or BadResource)
+ }
+ await this.#status;
+ }
+
ref() {
- this.#unrefed = false;
core.refOp(this.#waitPromiseId);
if (this.#stdout) readableStreamForRidUnrefableRef(this.#stdout);
if (this.#stderr) readableStreamForRidUnrefableRef(this.#stderr);
}
unref() {
- this.#unrefed = true;
core.unrefOp(this.#waitPromiseId);
if (this.#stdout) readableStreamForRidUnrefableUnref(this.#stdout);
if (this.#stderr) readableStreamForRidUnrefableUnref(this.#stderr);