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

  1. await using

    await using for async disposal, including thrown bodies, SuppressedError, and LIFO cleanup order.

  2. Database transaction

    The TC39 motivating case on a real IndexedDB object store: commit on success, abort and roll back on failure.

  3. AbortController scope

    Wrap an AbortController as an AsyncDisposable; scope exit aborts every in-flight task and surfaces the shared AbortSignal.reason.

  4. Stream reader lock

    The classic reader.releaseLock()-forgotten leak. Side-by-side wrapped vs unwrapped — watch the leak counter.

  5. Component Lifecycle

    A custom element that mounts an IntersectionObserver, ResizeObserver, and a timer into an AsyncDisposableStack on connectedCallback. One disposeAsync() call on disconnectedCallback tears everything down. Mount and unmount components to see each resource register and clean up in the log.

  6. Timeout Scope

    Pair AbortSignal.timeout() with await using: the AsyncDisposableStack holds an AbortController that 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

references