DEV Community

loading...

Discussion on: Generators in Javascript: How to use them

Collapse
destroyer22719 profile image
Nathan Cai

isn't this pretty similar to async/await?

Collapse
karimelghamry profile image
Karim Elghamry Author • Edited

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.