Skip to content

Instantly share code, notes, and snippets.

View conrad619's full-sized avatar

Conrad Reyes conrad619

View GitHub Profile
@conrad619
conrad619 / async-foreach.js
Created January 5, 2021 13:04 — forked from atinux/async-foreach.js
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (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)