26 ms·
checkout Koa to see a great use case of generators. By yielding to asychronous code (instead of callbacks) you can write JS that looks like it's synchronous.
by heifer2822 11y ago
checkout Koa to see a great use case of generators. By yielding to asychronous code (instead of callbacks) you can write JS that looks like it's synchronous.
- NikolaeVarius 11y agoWhat is the advantage of using generators versus promises?
- callahad 11y agoIn this case, Koa uses generators and promises together to emulate the behavior of async/await style concurrency. You can see how Babel 5.x transforms ES7 async/await into generators and promises at https://github.com/babel/babel/blob/v5.8.34/packages/babel/src/transformation/templates/helper-async-to-generator.js https://github.com/babel/babel/blob/v5.8.34/packages/babel/s...
- chowes 11y agohttp://stackoverflow.com/a/28032438 http://stackoverflow.com/a/28032438 gives a great overview to the pros and cons of both approaches.