mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
feat: explicit resource management in TypeScript (#20506)
This adds support for `using` and `await using` declarations in TypeScript only. We need to wait for v8 to support it for this to work in JS.
This commit is contained in:
parent
e66d3c2c2e
commit
6dc8682b9a
6 changed files with 39 additions and 3 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -958,9 +958,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_ast"
|
||||
version = "0.29.1"
|
||||
version = "0.29.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8bb902bcaa072210ca7b2f28c391f77bb16f6ef64664331c5d928d99943303c"
|
||||
checksum = "577ec3850834c2578eb44afa9250f9a807f8497664e6e2aaae19cea0aac2fe3b"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.13.1",
|
||||
|
|
|
@ -38,7 +38,7 @@ license = "MIT"
|
|||
repository = "https://github.com/denoland/deno"
|
||||
|
||||
[workspace.dependencies]
|
||||
deno_ast = { version = "0.29.1", features = ["transpiling"] }
|
||||
deno_ast = { version = "0.29.3", features = ["transpiling"] }
|
||||
|
||||
deno_core = { version = "0.211.0" }
|
||||
|
||||
|
|
|
@ -4701,3 +4701,8 @@ console.log(returnsHi());"#,
|
|||
")
|
||||
.assert_exit_code(1);
|
||||
}
|
||||
|
||||
itest!(explicit_resource_management {
|
||||
args: "run --quiet --check run/explicit_resource_management/main.ts",
|
||||
output: "run/explicit_resource_management/main.out",
|
||||
});
|
||||
|
|
5
cli/tests/testdata/run/explicit_resource_management/main.out
vendored
Normal file
5
cli/tests/testdata/run/explicit_resource_management/main.out
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
A
|
||||
Disposed
|
||||
B
|
||||
Async disposed
|
||||
C
|
21
cli/tests/testdata/run/explicit_resource_management/main.ts
vendored
Normal file
21
cli/tests/testdata/run/explicit_resource_management/main.ts
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Resource {
|
||||
[Symbol.dispose]() {
|
||||
console.log("Disposed");
|
||||
}
|
||||
}
|
||||
class AsyncResource {
|
||||
async [Symbol.asyncDispose]() {
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
console.log("Async disposed");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
using resource = new Resource();
|
||||
console.log("A");
|
||||
}
|
||||
{
|
||||
await using resource = new AsyncResource();
|
||||
console.log("B");
|
||||
}
|
||||
console.log("C");
|
|
@ -71,6 +71,11 @@ import {
|
|||
workerRuntimeGlobalProperties,
|
||||
} from "ext:runtime/98_global_scope.js";
|
||||
|
||||
// deno-lint-ignore prefer-primordials
|
||||
Symbol.dispose ??= Symbol("Symbol.dispose");
|
||||
// deno-lint-ignore prefer-primordials
|
||||
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
|
||||
|
||||
let windowIsClosing = false;
|
||||
let globalThis_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue