Skip to content

Instantly share code, notes, and snippets.

@nairihar
Last active May 20, 2018 14:40
Show Gist options
  • Save nairihar/a0cf193840af338883fa0ff9747772e5 to your computer and use it in GitHub Desktop.
Save nairihar/a0cf193840af338883fa0ff9747772e5 to your computer and use it in GitHub Desktop.
for-await-of, Async Iterator in NodeJS v10, medium
function myPromise(t) {
return new Promise((r) => {
setTimeout(() => {
r(t);
}, t);
});
}
const arr = [myPromise(2000), myPromise(500), myPromise(400)]; // iterable object
(async () => {
for await (const v of arr) { // iterates over the arr
console.log(v);
}
})();
// 2000, 500, 400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment