1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 10:07:54 -05:00
denoland-deno/cli/tests/testdata/run/explicit_resource_management/main.ts
David Sherret 6dc8682b9a
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.
2023-09-14 18:08:59 +00:00

21 lines
381 B
TypeScript

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");