Skip to content

Instantly share code, notes, and snippets.

@simevidas
Last active July 24, 2018 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simevidas/bd96e7255b59bec55241a4a9d18ac033 to your computer and use it in GitHub Desktop.
Save simevidas/bd96e7255b59bec55241a4a9d18ac033 to your computer and use it in GitHub Desktop.
// pattern 1
await Promise.all(
files.map(async file => {
let fileSize = await getSize(file);
totalSize += fileSize;
})
);
// pattern 2
let fileSizes = await Promise.all(
files.map(async file => getSize(file))
);
for (let fileSize of fileSizes) {
totalSize += fileSize;
}
// Too Terse Too Unreadable 1
for (let fileSize of await Promise.all(files.map(getSize))) {
totalSize += fileSize;
}
// Too Terse Too Unreadable 2
totalSize = (
await Promise.all(files.map(getSize))
).reduce((t, s) => t + s, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment