Symbol.asyncDispose

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The Symbol.asyncDispose static data property represents the well-known symbol Symbol.asyncDispose. The await using declaration looks up this symbol on the variable initializer for the method to call when the variable goes out of scope.

Value

The well-known symbol Symbol.asyncDispose.

Property attributes of Symbol.asyncDispose
Writableno
Enumerableno
Configurableno

Description

An object is async disposable if it has the [Symbol.asyncDispose]() method. The method is expected to have the following semantics:

  • Invoking this method notifies the AsyncDisposable object that the caller does not intend to continue to use this object. This method should perform any necessary logic to explicit clean up the resource including, but not limited to, file system handles, streams, host objects, etc.
  • This method can return a promise, which will be awaited before continuing.
  • When an exception is thrown from this method, it typically means that the resource could not be explicitly freed. An AsyncDisposable object is not considered "disposed" until the resulting Promise has been fulfilled.
  • If called more than once on the same object, the function should not throw an exception. However, this requirement is not enforced.

Examples

User defined async disposables

[Symbol.asyncDispose] allows the creation of custom async disposables. See the await using reference for more information.

js
class Disposable {
  #fileHandle;
  #disposed;

  constructor(handle) {
    this.#disposed = false;
    this.#fileHandle = handle;
  }

  async [Symbol.asyncDispose]() {
    await this.#fileHandle.close();
    this.disposed = true;
  }

  get isDisposed() {
    return this.disposed;
  }
}

const resource = new Disposable(await fs.open("my-file.txt", "r"));
{
  await using resourceUsed = resource;
  console.log(resource.isDisposed); // false
}
console.log(resource.isDisposed); // true

Specifications

Specification
ECMAScript Async Explicit Resource Management
# table-1

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
asyncDispose
Chrome – Full support
Chrome 127 (Release date: 2024-07-23)
footnote Full support
Edge – Full support
Edge 127 (Release date: 2024-07-25)
footnote Full support
Firefox – Full support
Firefox 141 (Release date: 2025-07-22)
footnote Full support
Opera – Full support
Opera 113 (Release date: 2024-08-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 127 (Release date: 2024-07-23)
footnote Full support
Firefox for Android – Full support
Firefox for Android 141 (Release date: 2025-07-22)
footnote Full support
Opera Android – Full support
Opera Android 84 (Release date: 2024-08-26)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 28 (Release date: 2025-04-02)
footnote Full support
WebView Android – Full support
WebView Android 127 (Release date: 2024-07-23)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Bun – Full support
Bun 1.0.23 (Release date: 2024-01-16)
footnote Full support
Deno – Full support
Deno 1.37 (Release date: 2023-09-20)
footnote Full support
Node.js – Partial support
Node.js 18.18 – 18.20 (Release date: 2023-09-18)
footnote Removed in 19 and later
footnote Partial support
footnote Only available for fs and stream resources.
Node.js – Partial support
Node.js 20.4 – 20.17 (Release date: 2023-07-05)
footnote Removed in 21 and later
footnote Partial support
footnote Only available for fs and stream resources.
Node.js – Full support
Node.js 24 (Release date: 2025-05-06)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Has more compatibility info.

See also