Async Generators

In notebook:
FrontEndMasters Async Javascript
Created at:
Fundamentals JavaScript
The outside is just plumbing, hidden in library somewhere. 

The app logic is inside the ​coroutine​ (the ​yield​ statements)

The benefit compared to thunks or promises or callbacks is flow control. The code is asynchronous looking, easy for our brains to understand.

We factored out asynchronicity to an implementation detail. 

Don't forget that JavaScript is single-threaded. So there's still only one line of code executing. Web workers is a different story.

Reply to question: if the generator is not in a paused state, and you want to iterate it, it will throw an error. So it it's paused, and two different calls are made to ​.next()​ (through a ​setTimeout​ for example), you will get an error. You will get out sequence.
Firefox put generators into FF about 10 years ago, before it became a standard. 

Use case: writing test cases for Firefox. Everything in the UI is async, so he had to use timeouts to write test cases. Then a colleague proposed him generators.
He writes 100% of his async code with generators. He doesn't use promise chains at all. Didn't find a single use case where promise chains would be better.