Closed
Description
π Search Terms
using
π Version & Regression Information
I assume it is in every version that using
has been implemented
β― Playground Link
π» Code
(async () => {
const log = [];
const promiseDispose = new Promise((resolve, _) => {
setTimeout(() => {
log.push("y dispose promise body");
resolve();
}, 0);
});
{
await using x = {
async [Symbol.asyncDispose = Symbol.for("Symbol.asyncDispose")]() {
log.push("x asyncDispose body");
},
};
await using y = {
[Symbol.dispose = Symbol.for("Symbol.dispose")]() {
log.push("y dispose body");
return promiseDispose;
},
};
}
log.push("body");
await promiseDispose;
console.log(log);
})();
π Actual behavior
It logs ["y dispose body", "y dispose promise body", "x asyncDispose body", "body"]
π Expected behavior
It should log ["y dispose body", "x asyncDispose body", "body", "y dispose promise body"]
.
The "y dispose promise body" should be printed in the next event cycle, however it is printed before x asyncDispose body
because the promise is awaited when disposing y
.
Additional information about the issue
Per 7.5.6 GetDisposeMethod
NOTE: This function is not observable to user code. It is used to ensure that a Promise returned from a synchronous dispose method will not be awaited.
cc @rbuckton