This might sound weird to you, the first thing that comes to mind is: 'Eslint will tell me to remove the await, there is no need for an await after...
For further actions, you may consider blocking this person and/or reporting abuse
In my opinion, you should almost never return a promise from an async function. You should
return awaitinstead. Not only does that cover this case naturally, it also improves async stack traces for debugging.Returning a promise from an async function is still needed if you want to run several operations in parallel, isn't it? That optimization comes up fairly frequently in my code when I tune its performance.
Why can you not run multiple functions in parallel if they're awaited? 🤔
That's right, that's a good use case for returning a promise without
await, thanks for the clarification 🙏I think it’s pretty common to call another async function at the end of your async function and return the result. As in the example. In that case there’s no way around it.
Interesting, Are you disabling the Eslint rule then?
Async await is more convenient than Promise chains, but I don't see why you wouldn't use Promise.catch in the example.
You could, this example is pretty simple so you're right, but for more complex logic try and catch is usually more convinient
Great post! It was short, easy to understand, and easy to see the advantage of organizing the code you propose.
Thank you Martin! I appreciate it :)
I could not fully understand the purpose if this blog.
Yeah I don't get the pros and cons of using it. I didn't even know you could do that, and I'm unsure exactly why I would or would not want to in the context of a try block, based on reading this blog post.
The main pro is being able to catch the error. I don’t see a con.
This is a specific use case for when you return a promise
To share a bug I had where I didn’t use await when I returned a promise and I couldn’t understand why my console log in the catch didn’t print