Created
June 15, 2019 18:08
-
-
Save llimacruz/aeda8ecce7663d17f9a98c9eaa184f40 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
const simuladorDeFuncaoAssincrona = (index, ms) => new Promise(resolve => { | |
setTimeout(() => { | |
console.log('executando funcao assincrona', index) | |
resolve() | |
}, ms) | |
}); | |
// [1, 2, 3].forEach(async (num) => { | |
// await waitFor(500); | |
// console.log(num); | |
// }); | |
// console.log('Done'); | |
const asyncForEach = async (array, callback) => { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
} | |
} | |
const metodoController = async () => { | |
const arrayNumbers = [1, 2, 3]; | |
await asyncForEach(arrayNumbers, async (num) => { | |
await simuladorDeFuncaoAssincrona(num, 1000); | |
}) | |
console.log('depois') | |
} | |
metodoController(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment