An introduction to how generators can be leveraged to flatten asynchronous code into a more manageable structure.
It comprises two basic exercises, the first of which illustrates how Promise-based code can be de-cluttered using generators to 'await' on promises. In the other example, we build our own miniature version of the library used in the first project (co
) to understand how it actually works under the hood.
In order to run the projects in this repo you'll need to have a version of node (>=4.0.0
) installed (you can check your version by entering node -v
in a command prompt). You can get the installer from here if you don't have node yet, or want to update.
You'll also need git (or a git client) to clone this repo.
Each folder contains a mini-project with it's own README which explains some of the concepts being illustrated, and how to complete each exercise, if you want to try it for yourself.
Completed versions of each of the projects will be found on the completed
branch if you just want to skip to a finished version and look at, or play with, the code.
Project walkthroughs:
- Koa - a web framework (currently) based on generators, using co.
- Generators are iterators and iterables - in-depth coverage of the
iterable
anditerator
protocols, including generator objects. - Async/await today with babel - a small article covering the basic setup of writing similarly flattened async code using the upcoming async/await syntax by transpiling with babel.