Last active
February 24, 2018 17:48
-
-
Save A6Brgeuka/89ecf83365d1f5e0825baf2ae65e4955 to your computer and use it in GitHub Desktop.
async-for-each
This file contains hidden or 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
export default async (array, callback) => { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array) | |
} | |
} |
This file contains hidden or 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
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