1. 6
    Use JavaScript (ES6) generators with Promises to handle async flows
    6m 52s

Use JavaScript (ES6) generators with Promises to handle async flows

Max Stoiber
InstructorMax Stoiber

Share this video with your friends

Send Tweet

With one tiny utility function we’ll unlock the full power of generators to make them work well with Promises and thus be the perfect weapon for asynchronous flows in our apps.

Pawel Grzybek
Pawel Grzybek
~ 4 years ago

Fantastic course! Short and easy to watch / understand with a morning coffee. The last lesson enlightened me a lot — finally I understand the inner logic of async / await functions which in my eyes are essentially a combination of promises and generators. Thanks a ton for this course, looking forward for more your resources! Have a great day.

Max Stoiber
Max Stoiberinstructor
~ 4 years ago

Thank you for the kind words, glad you enjoyed it 😊

Paul Vincent Beigang
Paul Vincent Beigang
~ 4 years ago

How does a comparison between generators and observables look like?

Raphi
Raphi
~ 4 years ago

Hi Max,

The videos were informative. I'm wondering however, in your last video where you use generators and Promises together to fetch some data, wouldn't it be much simpler to just use Promises in that fetchQuote generator (or rather, fetchQuote function)?

I fail to see what the generator+Promises adds in this case. Perhaps you were just trying to give an idea of the capabilities but used a not so stellar example.

Anshuman
Anshuman
~ 4 years ago

A Promise-based implementation of fetchQuote() would consist of a chain of .then() calls. While there is nothing wrong with that, using yield instead allows you to write code that looks almost like a synchronous version of fetchQuote() would.

Imagine that fetch() is synchronous and picture the body of fetchQuote() without the yield keyword.

Victor Hazbun
Victor Hazbun
~ 4 years ago

THIS IS AMAZING!

Alex
Alex
~ 3 years ago

good course last lesson could be done with await and it would work, it would be good if you would incorporate side effect on yields to show why this could be better used.

redux-saga for examples provides great use cases for generators.

Austin Hunt
Austin Hunt
~ a year ago

Doesn't async await make this no longer very useful?

Niv B
Niv B
~ a year ago

@Austin In did, but even now there are some enterprises and system codes still writing like.