Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. const simuladorDeFuncaoAssincrona = (index, ms) => new Promise(resolve => {
  2. setTimeout(() => {
  3. console.log('executando funcao assincrona', index)
  4. resolve()
  5. }, ms)
  6. });
  7.  
  8. // [1, 2, 3].forEach(async (num) => {
  9. // await waitFor(500);
  10. // console.log(num);
  11. // });
  12. // console.log('Done');
  13.  
  14. const asyncForEach = async (array, callback) => {
  15. for (let index = 0; index < array.length; index++) {
  16. await callback(array[index], index, array);
  17. }
  18. }
  19.  
  20.  
  21. const metodoController = async () => {
  22. const arrayNumbers = [1, 2, 3];
  23.  
  24. await asyncForEach(arrayNumbers, async (num) => {
  25. await simuladorDeFuncaoAssincrona(num, 1000);
  26. })
  27. console.log('depois')
  28. }
  29.  
  30. metodoController();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement