I’m still confused at some of the advantages of ES6 Generators. How does,
app.use(function *(next){
var start = new Date;
yield next;
var ms = new Date - start;
this.set('X-Response-Time', ms + 'ms');
});
compare to something like,
app.use(function (next, ctx) {
var start = new Date;
next(ctx);
var ms = new Date - start;
ctx.set('X-Response-Time', ms + 'ms');
});
What makes generators so special for something like Koa? This is what Koa.js has to say about generators,
Contrasting Connect’s implementation which simply passes control through series of functions until one returns, Koa yields “downstream”, then control flows back “upstream”.
Isn’t that what my above pseudo code does?