Last active
April 8, 2019 08:18
-
-
Save anthify/0f5679f1863f9038305e9a9d354444e4 to your computer and use it in GitHub Desktop.
Async Await forEach loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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