summaryrefslogtreecommitdiff
path: root/ext/fetch/22_http_client.js
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2023-12-06 16:52:59 +0900
committerGitHub <noreply@github.com>2023-12-06 16:52:59 +0900
commitdadd8b3d660fd2fd56803f29e1d8b6dd7a2adde9 (patch)
tree011a23d81af0ffd123c83cf47ed31c2338f377d9 /ext/fetch/22_http_client.js
parent65993e5efa5931c7a50b1fe926a0fa43eae0ca13 (diff)
feat(ext/fetch): allow `Deno.HttpClient` to be declared with `using` (#21453)
This commit adds a method of `Symbol.dispose` to the object returned from `Deno.createHttpClient`, so we can make use of [explicit resource management](https://github.com/tc39/proposal-explicit-resource-management) by declaring it with `using`.
Diffstat (limited to 'ext/fetch/22_http_client.js')
-rw-r--r--ext/fetch/22_http_client.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/ext/fetch/22_http_client.js b/ext/fetch/22_http_client.js
index 9d37f1b7f..45f5de80e 100644
--- a/ext/fetch/22_http_client.js
+++ b/ext/fetch/22_http_client.js
@@ -12,6 +12,7 @@
const core = globalThis.Deno.core;
const ops = core.ops;
+import { SymbolDispose } from "ext:deno_web/00_infra.js";
/**
* @param {Deno.CreateHttpClientOptions} options
@@ -33,9 +34,14 @@ class HttpClient {
constructor(rid) {
this.rid = rid;
}
+
close() {
core.close(this.rid);
}
+
+ [SymbolDispose]() {
+ core.tryClose(this.rid);
+ }
}
const HttpClientPrototype = HttpClient.prototype;