DEV Community

Discussion on: Understanding Generators in ES6 Javascript

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

I understand how they work, but I still have no idea where to use a generator.

Collapse
 
tuanphungcz profile image
Tuan Phung ⚡️

I will write another post with examples where generators come in handy

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Seems people agree. Unrelated: I also hate that you can't restart a generator. Despite the initial spec saying you could.

Thread Thread
 
tuanphungcz profile image
Tuan Phung ⚡️

I finally got some time, so I wrote down one example for the usage of generators, hope that you'll enjoy reading it 👉dev.to/phung_cz/canceling-promises...

Collapse
 
rtk profile image
RouvenKruse

The only scenario I can think of is using an asynchronous generator in combination with the "for await ... of" loop (developer.mozilla.org/en-US/docs/W...) when not using libraries such as rxjs.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Interesting! I didnt know about for await of and I thought I had mastered async await :/

Collapse
 
zee786 profile image
zee786

redux-sagas used a lot of generator functions