Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Promise.all(resourcePromises).then(function(values)
  2. {
  3. console.log(values);
  4. });
  5.  
  6. Promise.all(promises.map(Promise.all)).then(function(values) {
  7. console.log(values);
  8. });
  9.  
  10. function deepAll(array) {
  11. if (array instanceof Promise)
  12. // Just in case...
  13. return array;
  14. else if (array.length == 0)
  15. // The 'real' function will fail with an empty array and it's the same in both cases anyhow.
  16. return [];
  17. else if (Array.isArray(array[0]))
  18. // There's another array level, so turn it into an array of promises.
  19. return array.map(deepAll);
  20. else
  21. // This is an array of promises, and we already have a function for that case.
  22. return Promise.all(array);
  23. }
  24.  
  25. deepAll(promises).then(function(values) {
  26. console.log(values);
  27. });
  28.  
  29. function *deepWalk(arr) {
  30. for (var item of arr) {
  31. if (Array.isArray(item))
  32. yield* deepWalk(item)
  33. else
  34. yield item;
  35. }
  36. }
  37.  
  38. Promise.all(deepWalk(resourcePromises)).then(...
  39.  
  40. const balancePromises = [...];
  41. const symbolPromises = [...];
  42.  
  43. const [balances, symbols] = await Promise.all([
  44. Promise.all(balancePromises),
  45. Promise.all(symbolPromises)
  46. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement