re: All (or just most) of what you need to know about handling Promises VIEW POST

re: Oh, now I understand. Wow, this is worth editing the original post! Thanks!

Another improvement you can make is not using anonymous function
It gives you testability and readability
So instead of:

console.log(data); // logs: longPromise resolved
return shortPromise();
console.log(data) // logs: shortPromise resolved
.catch((error)=> {

you can do:
async function firstHandler(data){
return shortPromise()


But wouldn't this example start to get ugly if you had more that just 2 Promises?


looks ok to me
any how I'd go with async await today as much as I can, only use native promises if I need to wrap a callback from a library or something like that

Nice combo.
So you are actually chaining them asynchronously?

what do you mean?
you can't processData before you got the data, so it has to be done in series
getData() has to return a promise, the rest of the functions would automatically be converted to async

So why in your firstHandler example did you made the function to be async?

If you use it elsewhere, and it is async, mark it as async.
only when I use anonymous function directly in the chain I won't mark methods with async unless I have to.

code of conduct - report abuse