Skip to content

Instantly share code, notes, and snippets.

@anthify
Last active April 8, 2019 08:18
Show Gist options
  • Save anthify/0f5679f1863f9038305e9a9d354444e4 to your computer and use it in GitHub Desktop.
Save anthify/0f5679f1863f9038305e9a9d354444e4 to your computer and use it in GitHub Desktop.
Async Await forEach loop
export default async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
// example
import forEach from '.';
const paths = [...];
const storeFile = new Promise(...);
await forEach(paths, async (path, index) => {
await storeFile(path, index);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment