Skip to content

Instantly share code, notes, and snippets.

@ferreiratiago
Created June 14, 2018 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferreiratiago/79e28ef1c66a3ac27c079463695727ab to your computer and use it in GitHub Desktop.
Save ferreiratiago/79e28ef1c66a3ac27c079463695727ab to your computer and use it in GitHub Desktop.
for...of example
var iterable = {
[Symbol.iterator]: function* generatorWithPromise() {
// define an array of async data
const promises = [Promise.resolve(1), Promise.resolve(2)];
while (promises.length) {
yield promises.shift();
}
}
};
for (item of iterable) {
item.then(console.log);
}
console.log("done");
// done <- it should be the last to be printed
// 1
// 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment