Created
August 13, 2020 19:14
-
-
Save DavidWells/7165247047d18a7faa80b36f2dbbc1f1 to your computer and use it in GitHub Desktop.
This file contains 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
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