Advertisement
Guest User

Untitled

a guest
May 25th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. const LIST = ['Orange', 'Lemon', 'Banana' ]
  2.  
  3. process(LIST);
  4.  
  5. async function eachAsync(arr, fn) { // take an array and a function
  6. for(const item of arr) await fn(item);
  7. }
  8.  
  9. async function process(list) {
  10. await eachAsync(list, async (data) => {
  11. let result = await print(data)
  12. console.log(result)
  13. });
  14.  
  15. console.log('Done');
  16. }
  17.  
  18. function print(data) {
  19. return new Promise((resolve, reject) => {
  20. setTimeout(() => {
  21. console.log(data);
  22. resolve("Data was sent")
  23. }, 3000)
  24. });
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement