Created
March 3, 2019 10:59
-
-
Save LissetteIbnz/3e66354d091ab719b0b0633c2026c91f to your computer and use it in GitHub Desktop.
async forEach
This file contains 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
async function asyncForEach(array, callback) { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
} | |
} | |
const start = async () => { | |
await asyncForEach([1, 2, 3], async (num) => { | |
await waitFor(50); | |
console.log(num); | |
}); | |
console.log('Done'); | |
} | |
start(); | |
$ node asyncForEach.js | |
$ 1 | |
$ 2 | |
$ 3 | |
$ Done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment