Write Your Own Co Using ES2015 Generators

ES2015 is now officially the new JavaScript language standard, and it is packed with sweet new features. One feature that I’m particularly excited about is ​generators​. At a high level, generators are functions that can pause and then pick up where they left off later. Generators enable you to break up CPU­-intensive calculations like computing the millionth Fibonacci number so you don’t block the event loop and write ​web servers using middleware that can post-­process your HTTP response​. The most exciting application of generators, though, is asynchronous coroutines, better known as callback-­free asynchronous code. In this article, you’ll learn about how to write your own ​co​, a library for asynchronous coroutines using generators.
Read more