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.
The well-known symbol Symbol.asyncDispose.
Property attributes of Symbol.asyncDispose
| |
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | no |
An object is async disposable if it has the [Symbol.asyncDispose]() method. The method is expected to have the following semantics:
[Symbol.asyncDispose] allows the creation of custom async disposables. See the await using reference for more information.
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
| Specification |
|---|
| ECMAScript Async Explicit Resource Management> # table-1> |
| 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 |
127 | 127 | 141 | 113 | No | 127 | 141 | 84 | No | 28.0 | 127 | No | 1.0.23 | 1.37 |
24.0.020.4.0–21.0.0Only available forfs and stream resources.18.18.0–19.0.0Only available forfs and stream resources. |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncDispose