Skip to content

Instantly share code, notes, and snippets.

@nashibao
Last active January 2, 2016 10:59
Show Gist options
  • Save nashibao/8293370 to your computer and use it in GitHub Desktop.
Save nashibao/8293370 to your computer and use it in GitHub Desktop.
for study.
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