-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do we need using await const
in an async function?
#68
Comments
Hi @rbuckton thanks for asking. It does. In fact, I remain extremely uncomfortable at how weak this is as an interleaving marker to mark an interleaving point which is textually distant and not otherwise marked. However, with the The "novel syntax" doesn't help at all. Ten years from now, it'll just be part of the endless sea of "too much syntax" that all JS programmers suffer with. https://erights.medium.com/the-tragedy-of-the-common-lisp-why-large-languages-explode-4e83096239b9 The current state is that only two keywords mark interleaving points: |
I appreciate the feedback, thanks! |
I am concerned that dropping In the example above, it's not clear that the block where async function foo() {
/*a*/
{
// Potentially some code here
using const asyncResource = getAsyncResource(); // has @@asyncDispose
// More code here
// implicit `await asyncResource[@@asyncDispose]()`
}
// ...
} Compare that to an explicit marker on the containing block (completely arbitrary syntax suggestion): async function foo() {
/*a*/
do {
// Potentially some code here
// Note the use of `async` here instead of `await` as there is no interleaving point
using async const asyncResource = getAsyncResource(); // has @@asyncDispose
// More code here
// explicit interleaving point for `await asyncResource[@@asyncDispose]()`
} await dispose;
// ...
}
|
We've previously discussed the hidden interleaving point in If enforced syntactically it becomes a refactoring hazard. Moving code around within a block would now require additional non-local changes to that code move. I'd much rather pick a single consistent syntax over having two different ways of doing the same thing (i.e., not having both Finally, It would be perfectly feasible for a linter to enforce a rule that states a block with a |
Right, but at least there is a marker on the block. And since
I'm not sure I follow. Within a block there is no hazard. It would be moving code from a block with marker to a block without. And regardless, if there is syntax missing, the error will be caught by linters and the executing engine.
But a comment is not code. A In my mind this problem of marking the block is similar to not being able to use |
I'm not entirely sure what direction to take with this, then. We've already discussed The mitigation strategy for handling the implicit interleaving point were:
This was the consensus as of Feb, 2020, and is the direction I've been taking since (in between other tasks). |
I wasn't at the Feb 2020 plenary (or an active TC39 delegate then). If there was consensus on removing any block marking, then that's how it is. I am in favor of the |
|
Right, but as I mentioned the place of the |
The
await
keyword was added totry using
in response to concerns from @erights regarding hidden interleaving points in code execution. While I'm not opposed to keeping it in, I'm curious if @erights or others would have a strong opposition to removing and having@@asyncDispose
invoke at the end of the block, if present on a resource:While its true this would inject an implicit
await
when the block (a) closes, would this consequence possibly be ameliorated by the fact thatusing const
is novel syntax?using const
itself already introduces implicit code evaluation at the end of the block, so its not a stretch to also explain thatusing const
will Await an@@asyncDisposable
resource at the end of the block as well.@erights, if your concern still stands in light of this, I'm happy to leave
using await const
in. If not, it would be nice to remove theawait
keyword as unnecessary ceremony.The text was updated successfully, but these errors were encountered: