Last active
September 12, 2019 13:26
-
-
Save deadkff01/1060dc331cba89ce2a86ce9d7a7fb142 to your computer and use it in GitHub Desktop.
Simple example of async foreach
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
async function asyncForEach(array, callback) { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
} | |
} | |
const waitFor = ms => new Promise(r => setTimeout(r, ms)); | |
asyncForEach([1, 2, 3], async num => { | |
await waitFor(50); | |
console.log(num); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment