Last active
January 2, 2016 10:59
-
-
Save nashibao/8293370 to your computer and use it in GitHub Desktop.
for study.
This file contains 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 = function(fn){ | |
// callback | |
var done = function(val){ | |
// yieldに値を流し込む | |
gen.next(val); | |
} | |
// make a generator | |
var gen = fn(done); | |
// start | |
gen.next(); | |
}; | |
// test | |
// 0~4までをディレイ付きで表示する | |
co(function*(done){ | |
for(var i=0;i<5;i++){ | |
var val = yield setTimeout(function() { done(i); }, 500); | |
console.log('val: ', val); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment