5 ms·
He looked pretty ok with async/await (which uses Promises under the hood), one of the advertised features of his new project is top level await.
by Guillaume86 8y ago
He looked pretty ok with async/await (which uses Promises under the hood), one of the advertised features of his new project is top level await.
- spankalee 8y agoWhich is unfortunate. Top-level await is a very bad footgun and should almost never be used.
- tlrobinson 8y agoCan you elaborate? It seems useful for simple scripts and REPLs, at least.
- lostctown 8y agoIt is useful for those things. I implemented a fairly involved scripting system that we now use inside all of our server instances. Each script in the system is an entry file mapping to an alias command and the entry file is invoked from the top level. To get the benefits of async/await, we write the logic of each entry script under main = async () => do_logic(), and call it at the end of the file as main(). I just don't see how this workaround is the correct solution. Just saying that's it's generally a bad idea is not enough for me. At some point there will come a time when you want to treat a file as a function, and when that day comes you will want async/await at the top level.