Skip to content

Instantly share code, notes, and snippets.

@doubleOrt
Last active March 20, 2018 17:08
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 doubleOrt/598659adfefdd941f2a98512f0f7f078 to your computer and use it in GitHub Desktop.
Save doubleOrt/598659adfefdd941f2a98512f0f7f078 to your computer and use it in GitHub Desktop.
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