What happens if you mix then/catch and await for Promises in Javascript?
await thisReturnsAPromise()
.then(() => /* do something */)
.catch(() => /* do something */);
- Does it await the Promise twice? Once for the
await
and once for thethen
callback? - Does
then
return a new Promise or is it exactly the same as the function returns? - The
await
will resolve afterthen
, but are they resolved at the same time or is there a tiny delay between?
What is returned in this case and why?:
const awaitResult = await thisReturnsAPromise() // returns a Promise<number>
.then((thenResult) => /* do something */)
.catch(() => /* do something */);
It is clear that it is not ideal to mix the approaches so the question is what happens when you do.