Skip to content

Instantly share code, notes, and snippets.

@llimacruz
Created June 15, 2019 18:08
Show Gist options
  • Save llimacruz/aeda8ecce7663d17f9a98c9eaa184f40 to your computer and use it in GitHub Desktop.
Save llimacruz/aeda8ecce7663d17f9a98c9eaa184f40 to your computer and use it in GitHub Desktop.
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