Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ugultopu/376118b9b261cdaeb7f74694c652ddc5 to your computer and use it in GitHub Desktop.
Save ugultopu/376118b9b261cdaeb7f74694c652ddc5 to your computer and use it in GitHub Desktop.
async/await is just a convenient way of creating and using promises

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 of then callbacks (of promises), and try/catch around await expressions is the equivalent of a catch 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.

Sources

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment