That's it. async/await is not yet another technology for asynchronous programming in JavaScript. It is simply a wrapper, a syntactic sugar for promise creation. Quoting this post:
async
/await
is syntactic sugar around promise creation and consumption. It's really helpful sugar, but that's all it is.async
functions return promises,await
expressions are the equivalent ofthen
callbacks (of promises), andtry
/catch
aroundawait
expressions is the equivalent of acatch
callback (of promises).
The question "Is async/await just syntactic sugar for promises?" came to my mind when I was reading the API documentation for the fs
module of Node.js. In the documentation, there were two versions of every function (two versions when we exclude the "sync" versions). One of them was the good old callback based one and the other one was a new promise based one. Not seeing an async
/await
based one, I wondered where the async/await based one and thought that maybe async/await is nothing but simply syntactic sugar over promises. And lo and behold, it is. So, to sum it up, there are two ways of asynchronous programming in JavaScript:
- Using the good old callbacks.
- Promises.
async
/await
is nothing but a wrapper, a syntactic sugar for promises.
https://www.google.com/search?q=is+async+await+just+syntactic+sugar+for+promises https://stackoverflow.com/questions/48623837/how-does-using-async-await-differ-from-using-promises https://gist.github.com/joeytwiddle/ff0a9cf92be0366b274e4283a8b5a935