Last active
May 20, 2018 14:40
-
-
Save nairihar/a0cf193840af338883fa0ff9747772e5 to your computer and use it in GitHub Desktop.
for-await-of, Async Iterator in NodeJS v10, medium
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
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