Created
May 17, 2017 15:02
-
-
Save 7flash/370341b83ca07ccd66de5095ba459b45 to your computer and use it in GitHub Desktop.
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 = require('co'); | |
function getResult(item) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(item * 2); | |
}, 100); | |
}); | |
} | |
function* sequence() { | |
let i = 10; | |
let arr = []; | |
while(--i) { | |
arr.push(yield getResult(i)); | |
} | |
return arr; | |
} | |
co(function* () { | |
let result = yield sequence(); | |
console.log(result); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment