Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var waitFor = (ms) => new Promise(r => setTimeout(r, ms))
async function asyncForEach(array, callback) { 
for (let index = 0; index < array.length; index++) {   
await callback(array[index], index, array) 
}
}
var start = async () => { 
let state = 0 
await asyncForEach([1, 2, 3], async (num) => {   
await waitFor(1000)   
console.log(num)   
state = state + num 
}) 
console.log('Done') 
return state
}
start().then((res) => { 
console.log(res)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment