Re:V8 adds support for top-level await
by mstade on Wednesday September 25, 2019 @06:40AM
(#21069412)
You're right of course, and I have zero data to back this up other than anecdotes from my own experience, but still I posit the most common case is that the caller wants to await the return value, not run the function asynchronously. This is why I think it'd make more sense to flip the semantics so you'd have implicit await, and have to explicitly mark the things you want to run asynchronously.
[ Parent
| on HN ]
Re:V8 adds support for top-level await
by eyelidlessness on Thursday September 26, 2019 @03:25PM
(#21084522)
Implicit await would be a nightmare. You could never tell looking at a given block of code whether it yields to the event loop or not, introducing invisible concurrency problems. Even static types wouldn't solve this without looking at every value and function return type.
Would love to learn what concurrency issues you'd see with implicit await, that you presumably wouldn't see otherwise. You're probably right, I just can't think of any examples.
Re:V8 adds support for top-level await
by anonytrary on Wednesday September 25, 2019 @11:35PM
(#21077930)
I think there might be some confusion here. `foo()` will run asynchronously regardless of whether or not `await` is specified. I agree that in most cases, you will want to unbox the Promise. It is still very common to pass Promises around as values.