Skip to content

Instantly share code, notes, and snippets.

@doubleOrt
Last active Mar 20, 2018
Embed
What would you like to do?
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