Last active
January 2, 2016 13:49
-
-
Save ahomu/8312813 to your computer and use it in GitHub Desktop.
https://github.com/koajs/koa/blob/master/lib/application.js#L96
https://github.com/koajs/compose/blob/master/index.js#L27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var co = require('co'); | |
var stack = [ | |
function *first(next) { // second generator | |
console.log('1 prev'); | |
yield next; // second に delegate | |
console.log('1 next'); | |
}, | |
function *second(next) { // third generator | |
console.log('2 prev'); | |
console.log(next.constructor.name); | |
yield next; // third に delegate | |
console.log('2 next'); | |
}, | |
function *third(next) { // noop generator | |
console.log('3 prev'); | |
yield next; // noop に delegate | |
console.log('3 next'); | |
} | |
]; | |
co(function *() { | |
console.log('start'); | |
var prev = function *() {}; // noop generator | |
var i = stack.length; | |
while (i--) { | |
prev = stack[i].call(this, prev) | |
console.log('#' + (i+1) + '#'); | |
} | |
yield *prev; // first generator に delegate | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment