Skip to content

Instantly share code, notes, and snippets.

@LissetteIbnz
Created March 3, 2019 10:59
Show Gist options
  • Save LissetteIbnz/3e66354d091ab719b0b0633c2026c91f to your computer and use it in GitHub Desktop.
Save LissetteIbnz/3e66354d091ab719b0b0633c2026c91f to your computer and use it in GitHub Desktop.
async forEach
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