2 ms·
Hey, something is wrong with your interpreter or your transpiler if you need to wrap every `async` function in a `return new Promise`. If you mark a function as
by cprecioso 7y ago
Hey, something is wrong with your interpreter or your transpiler if you need to wrap every `async` function in a `return new Promise`. If you mark a function as `async` it will do it automatically - in fact, if you look at e.g. `nodent`'s output, it's exactly how it does it. Calling the `resolve` function instead a `then` callback like that is a mess, and totally not needed. Also, the `return` is not necessary, every function has an implicit `undefined` return if not explicitly stated.
Moreover, in async functions you can take advantage of regular `try`/`catch` when awaiting; it seems you're just swallowing errors in your functions, which I guess is fine for the code you're showing. But keep in mind that a better practice is to let those function throw and catch it with a try/catch at the callsite.
Lastly, when calling the functions to save and send the email, you can use `Promise.all` and parallelize them instead of running them serially, as they don't seem to depend on each other. If you're meaning to send the email only after it is saved, then you need to check the return value of the saving before that; because neither of the calls will ever fail; just return undefined.
- nikodunk 7y agoAh, excellent points. Thank you for the very carefully crafted comment. I will update once I've re-tested with these changes.