I tried to follow the reason await using thing = await that()
is anyhow desirable when using thing = await that()
would work practically the same ... can anyone please enlighten me around this topic?
const disposable = value => ({
value,
[Symbol.dispose]() {
console.log('disposed');
},
async [Symbol.disposeAsync]() {
await Promise.resolve();
console.log('disposed');
}
});
const testSync = () => {
using ref = disposable('sync');
console.log(ref.value);
};
const testAsync = async () => {
await using ref = disposable('async');
console.log(ref.value);
};
Why or when await using
does a better job than a Symbol.dispose
that returns an async function anyway?
const disposable = value => ({
value,
async [Symbol.dispose]() {
await Promise.resolve();
console.log('disposed');
}
});
Where is the observable need for wait in using
that makes any difference in there, when I believe a synchronous dispose that returns a promise (async function) would still run to completion once invoked?
Thanks in advance to anyone willing to explain the need for await using
as I really struggle to see why, what, or where that is better than just using
.