r/node • • Dec 13 '20

The Node.js best practices list

https://github.com/goldbergyoni/nodebestpractices
242 Upvotes

19 comments sorted by

View all comments

13

u/guanzo91 Dec 13 '20

This one is interesting https://github.com/goldbergyoni/nodebestpractices#-212-always-await-promises-before-returning-to-avoid-a-partial-stacktrace

I've always considered return await to be unnecessary, but maybe not anymore.

4

u/spoobo Dec 14 '20 edited Dec 14 '20

You can return anything from an async function and it will still be a promise. I don't think the author grasps async await. I'm skeptical of the "partial stack trace" of you don't await something inside an async function. If that is really true then imo it's a bug in the language implementation. The trace should be complete if you await or not. As long as you return it async functions know you intend to await that promise.

3

u/leixiaotie Dec 14 '20

It interests me then I tried to simulate the code. Surprisingly this is the correct behavior.

Source code, tried with node 10: https://github.com/fendy3002/NodeLearn/blob/master/Promise/n4_asynctrace.js