DEV Community

Discussion on: Generators in Javascript: How to use them

destroyer22719 profile image
Nathan Cai

isn't this pretty similar to async/await?

karimelghamry profile image
Karim Elghamry Author • Edited on

There are some key differences. One of the biggest differences is that after finishing the await call inside an async function, the function does not terminate nor return a value. Instead, it continues its execution normally. With generators however, you can pause and return values on demand using the yield keyword.

But if you actually think about it, they have so much in common. Actually, it is easy to replicate the behavior of async/await using generators. This article describes a brief idea on how to do this with little effort.