Last active
March 20, 2018 17:08
-
-
Save doubleOrt/598659adfefdd941f2a98512f0f7f078 to your computer and use it in GitHub Desktop.
This file contains 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
const foo = async function() { | |
const timeAtBeginning = new Date().getTime(); | |
const vals = []; | |
for(let a of [1, 2, 3]) { | |
vals.push( | |
await new Promise( r => setTimeout(r, 1000, a * 2) ) | |
); | |
} | |
const timeAtEnd = new Date().getTime() - timeAtBeginning; | |
console.log(vals, timeAtEnd); | |
}; | |
const bar = async function() { | |
const timeAtBeginning = new Date().getTime(); | |
const vals = await Promise.all( | |
[1, 2, 3].map( | |
async a => new Promise( r => setTimeout(r, 1000, a * 2) ) | |
) | |
); | |
const timeAtEnd = new Date().getTime() - timeAtBeginning; | |
console.log(vals, timeAtEnd); | |
}; | |
foo(); | |
bar(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment