4 ms·
If you could await in a regular function then that function would need to return a promise. But it would be confusing if adding an await keyword to the middle o
by nicoburns 5y ago
If you could await in a regular function then that function would need to return a promise. But it would be confusing if adding an await keyword to the middle of a function body implicitly changed it into returning a promise. Thus we enforce that you have to use the async keyword on the function in order to enable this functionality.
- endorphine 5y ago> If you could await in a regular function then that function would need to return a promise. Why would it have to return a promise?
- actually_a_dog 5y agoI understand where you're coming from. But, how would this be any more confusing than the fact that using yield instead of return in Python turns a function into a generator? That just seems like a pretty thin justification for not allowing await without async.
- nicoburns 5y agoI mean JavaScript makes the same decision here as well. To use yield you must define a generator using "function*" rather than a function using "function" exactly because it's confusing. Is it really so hard to to type `async`?
- actually_a_dog 5y agoThat's not a justification. Maybe JS used the same flawed reasoning?