Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I’m not an expert on Node.js but I was always under the impression that you couldn’t write await outside of an async function. Has that changed recently?


You can await at the top level of a module since node v14.8.

It has been proposed to Python: https://groups.google.com/g/python-ideas/c/PN1_j7Md4j0/m/0xy...

But I have no more info about it.


You are right that you can only await in an async function, but you can call an async function anywhere and get back a Promise.

await-ing that promise is often what you want to do but there are other ways to do work once the promise has resolved.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: