Skip to content

Instantly share code, notes, and snippets.

@A6Brgeuka
Last active February 24, 2018 17:48
Show Gist options
  • Save A6Brgeuka/89ecf83365d1f5e0825baf2ae65e4955 to your computer and use it in GitHub Desktop.
Save A6Brgeuka/89ecf83365d1f5e0825baf2ae65e4955 to your computer and use it in GitHub Desktop.
async-for-each
export default async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
import asyncForEach from './async-for-each'
console.log('start')
await start([1, 2, 3])
console.log('end')
async function start(array) {
await asyncForEach(array, async item => {
await waitFor(1000)
console.log(item)
})
}
function waitFor(ms) {
return new Promise(r => setTimeout(r, ms))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment