4 ms·
I started working in node around version 0.8, before both native Promises and async/await. I worked with guys that started after async/await. The new guys jus
by Osiris 5y ago
I started working in node around version 0.8, before both native Promises and async/await.
I worked with guys that started after async/await.
The new guys just think of everything like it's synchronous. They don't understand Promises. They never look at code and think "I can run this in parallel with Promise.all and a reducer". They just await each thing one at a time.
So, I'm not sure the async/await annotations are really helping us when devs just use them like decorations that just have to be there for it to work.
- z3t4 5y agoDon't forget to put each await in a try/catch. You are handling all errors aren't you!? ;)
- tsian2 5y agoI'm new to NodeJS but it was my understanding that using await like that would help by not blocking the thread, leaving node free to process other requests.
- gregoryjjb 5y agoawait won't block Node from handling other requests but it will block the thread that is awaiting. For example, these will execute one after the other (the "bad way"): await slowThingOne(); await slowThingTwo(); but these execute in parallel, awaiting until both are finished (the "good way"): await Promise.all([slowThingOne(), slowThingTwo()]);
- hmsimha 5y agoMinor clarification, the latter example will only await until both have resolved *or* one rejects. To await the resolution of all promises, you should use the truly gamechanging `Promise.allSettled` , though you will have to transpile it if it's not supported by your target environments.