Compare Async/Await and Generators usage to achive same functionality

Technology CommunityCategory: JavaScriptCompare Async/Await and Generators usage to achive same functionality
VietMX Staff asked 3 years ago
  • Generator function are executed yield by yield i.e one yield-expression at a time by its iterator (the next method) where as Async-await, they are executed sequential await by await.
  • Async/await makes it easier to implement a particular use case of Generators.
  • The return value of Generator is always {value: X, done: Boolean} where as for Async function it will always be a promise that will either resolve to the value X or throw an error.
  • Async function can be decomposed into Generator and promise implementation like: