DEV Community

Discussion on: Why to use async & await instead of the Promise class?

 
miksimal profile image
Mikkel

Good point re. simply returning a promise being the same here, thanks! I just pasted from a Lambda I was writing where I had a try/catch block and was returning some messages, so I needed the await before and didn't even think about removing it. E.g.:

     await client.put(params).promise();
     return { message: "Success! The headlines were: " + topHeadlines }

Re. splitting the function that's a good idea, thanks. This was a copy/paste from a quick and dirty Lambda function for a personal project, but I like how your promise chain rewrite is both easier to read and more testable. Will think twice next time instead of lazily reaching for my async/await 💪