Created
May 17, 2017 15:12
-
-
Save 7flash/112a8ff19c7148a729383fef3ef2cd4e to your computer and use it in GitHub Desktop.
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'); | |
let items = [1,2,3]; | |
function* getResult(item) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(item * 2), 100); | |
}); | |
} | |
co(function* () { | |
for(let item of items) { | |
let itemResult = yield getResult(item); | |
console.log(itemResult); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: in this case you should not use infinite sequence generator instead of items array because for-of loop is synchronous.