3 ms·
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?
by justusw 5y ago
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?
- shauns 5y agoYou 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.
- BiteCode_dev 5y agoYou 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/0xyn7RPuBAAJ https://groups.google.com/g/python-ideas/c/PN1_j7Md4j0/m/0xy... But I have no more info about it.