Skip to content

Instantly share code, notes, and snippets.

@gadflying
Forked from simevidas/totalsize.js
Created July 24, 2018 06:01
Show Gist options
  • Select an option

  • Save gadflying/79353d0285ed0c82565ed71046b47acf to your computer and use it in GitHub Desktop.

Select an option

Save gadflying/79353d0285ed0c82565ed71046b47acf 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