Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement