Promises and Generators: control flow utopia
summary
Claims that ES6 generators plus promises let asynchronous code read like synchronous code: actual implementation shows a small generator wrapper that resumes with generator.next or throw, yielding promises and propagating errors correctly. Demonstrates converting callback-style readFile/JSON parsing into promise-returning functions, then into generator + yield code that supports try/catch, for/loops and straightforward parallelism by starting promises before yielding. Compares failed alternatives (streamline, suspend, co) and shows the approach works in practice.
AI-written summary · about
chapters (9)
- 0:00Generators and lazy loops
- 2:43Asynchronous challenges
- 4:58Managing callback flaws
- 8:55Introduction to promises
- 9:49Streamlining with then
- 19:00Async await with generators
- 23:21How generators work
- 28:52Alternative async tools
- 30:54Conclusion
related talks
45mNext Generation Asynchronous Patterns in JavaScript
32mPromises Are So Passé
15mI Yield for Generators
32mJavaScript 7: the Evolution of JavaScript
33mAsync Functions Awaiting You
33mAsync Programming in ES7
41mNext Generation Asynchronous Patterns in JavaScript
22mFrom Promises through Generators to async/await in node.js
