Skip to content

Instantly share code, notes, and snippets.

@7flash
Created May 17, 2017 15:02
Show Gist options
  • Save 7flash/370341b83ca07ccd66de5095ba459b45 to your computer and use it in GitHub Desktop.
Save 7flash/370341b83ca07ccd66de5095ba459b45 to your computer and use it in GitHub Desktop.
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