4 ms·
This looks very useful, as it's already useful in other languages. I found the syntax a bit confusing though. `await` comes before a promise, except in this ca
by iansinnott 3y ago
This looks very useful, as it's already useful in other languages.
I found the syntax a bit confusing though. `await` comes before a promise, except in this case. I wonder what the reasoning behind the syntax was.
- jameshart 3y agoRight, given that await x is an expression which could already resolve to an object with a dispose function, it seems like ‘using await x’ would just work, without needing special ‘await using’ shenanigans.
- debugnik 3y agoIt's to distinguish whether to call res[Symbol.dispose]() or await res[Symbol.asyncDispose]() at the exit.
- osener 3y agoYou’re right, that is a curious design choice. For what it’s worth, I always thought this syntax for await felt more natural: let await user = getUser() But now we have it both ways for different use cases and it’s weird.
- saiojd 3y agoI agree. I feel like `using async x = ...` would read much more nicely and avoid the confusion.
- KwanEsq 3y agohttps://github.com/tc39/proposal-async-explicit-resource-management/issues/12 https://github.com/tc39/proposal-async-explicit-resource-man...
- WorldMaker 3y agoIt's marking that the disposal itself, when it comes time, needs to be awaited. Keep in mind, await may need to be in both sides: await using connection = await getConnection() If it was `using await` that might give some confusion if it was awaiting the left or right side or the future disposal. Similarly, it gets fun combined with AsyncIterable: for await (await using connection of getAllConnections()) { }