v131 · javascript
Explicit resource management (async)
This feature addresses a common pattern in software development regarding the lifetime and management of various resources (memory, I/O, etc.). This pattern generally includes the allocation of a resource and the ability to explicitly release critical resources.
concepts
-
await using
await usingfor async disposal, including thrown bodies,SuppressedError, and LIFO cleanup order. -
Database transaction
The TC39 motivating case on a real IndexedDB object store: commit on success, abort and roll back on failure.
-
AbortController scope
Wrap an
AbortControlleras anAsyncDisposable; scope exit aborts every in-flight task and surfaces the sharedAbortSignal.reason. -
Stream reader lock
The classic
reader.releaseLock()-forgotten leak. Side-by-side wrapped vs unwrapped — watch the leak counter. -
Component Lifecycle
A custom element that mounts an
IntersectionObserver,ResizeObserver, and a timer into anAsyncDisposableStackonconnectedCallback. OnedisposeAsync()call ondisconnectedCallbacktears everything down. Mount and unmount components to see each resource register and clean up in the log. -
Timeout Scope
Pair
AbortSignal.timeout()withawait using: theAsyncDisposableStackholds anAbortControllerthat fires whether the request succeeds or times out. Two side-by-side panels show a fast request completing cleanly vs a slow request being cancelled — adjust latency and timeout sliders to flip which scenario wins.
why it shipped
https://github.com/tc39/proposal-explicit-resource-management/blob/main/README.md