SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getUserId() {
  2.   return new Promise((resolve, reject) => {
  3.     setTimeout(() => {
  4.       resolve(Date.now())
  5.     }, 2000)
  6.   })
  7. }
  8.  
  9.  
  10. const users = [{
  11.   firstName: "Andreas",
  12.   lastName: "Iosifelis"
  13. }, {
  14.   firstName: "George",
  15.   lastName: "Iosifelis"
  16. },{
  17.   firstName: "Andreas",
  18.   lastName: "Iosifelis"
  19. }, {
  20.   firstName: "George",
  21.   lastName: "Iosifelis"
  22. },{
  23.   firstName: "Andreas",
  24.   lastName: "Iosifelis"
  25. }, {
  26.   firstName: "George",
  27.   lastName: "Iosifelis"
  28. },{
  29.   firstName: "Andreas",
  30.   lastName: "Iosifelis"
  31. }, {
  32.   firstName: "George",
  33.   lastName: "Iosifelis"
  34. },{
  35.   firstName: "Andreas",
  36.   lastName: "Iosifelis"
  37. }, {
  38.   firstName: "George",
  39.   lastName: "Iosifelis"
  40. },{
  41.   firstName: "Andreas",
  42.   lastName: "Iosifelis"
  43. }, {
  44.   firstName: "George",
  45.   lastName: "Iosifelis"
  46. },{
  47.   firstName: "Andreas",
  48.   lastName: "Iosifelis"
  49. }, {
  50.   firstName: "George",
  51.   lastName: "Iosifelis"
  52. },{
  53.   firstName: "Andreas",
  54.   lastName: "Iosifelis"
  55. }, {
  56.   firstName: "George",
  57.   lastName: "Iosifelis"
  58. },{
  59.   firstName: "Andreas",
  60.   lastName: "Iosifelis"
  61. }, {
  62.   firstName: "George",
  63.   lastName: "Iosifelis"
  64. },{
  65.   firstName: "Andreas",
  66.   lastName: "Iosifelis"
  67. }, {
  68.   firstName: "George",
  69.   lastName: "Iosifelis"
  70. },{
  71.   firstName: "Andreas",
  72.   lastName: "Iosifelis"
  73. }, {
  74.   firstName: "George",
  75.   lastName: "Iosifelis"
  76. },{
  77.   firstName: "Andreas",
  78.   lastName: "Iosifelis"
  79. }, {
  80.   firstName: "George",
  81.   lastName: "Iosifelis"
  82. },{
  83.   firstName: "Andreas",
  84.   lastName: "Iosifelis"
  85. }, {
  86.   firstName: "George",
  87.   lastName: "Iosifelis"
  88. },{
  89.   firstName: "Andreas",
  90.   lastName: "Iosifelis"
  91. }, {
  92.   firstName: "George",
  93.   lastName: "Iosifelis"
  94. },{
  95.   firstName: "Andreas",
  96.   lastName: "Iosifelis"
  97. }, {
  98.   firstName: "George",
  99.   lastName: "Iosifelis"
  100. },{
  101.   firstName: "Andreas",
  102.   lastName: "Iosifelis"
  103. }, {
  104.   firstName: "George",
  105.   lastName: "Iosifelis"
  106. },{
  107.   firstName: "Andreas",
  108.   lastName: "Iosifelis"
  109. }, {
  110.   firstName: "George",
  111.   lastName: "Iosifelis"
  112. },{
  113.   firstName: "Andreas",
  114.   lastName: "Iosifelis"
  115. }, {
  116.   firstName: "George",
  117.   lastName: "Iosifelis"
  118. },{
  119.   firstName: "Andreas",
  120.   lastName: "Iosifelis"
  121. }, {
  122.   firstName: "George",
  123.   lastName: "Iosifelis"
  124. },{
  125.   firstName: "Andreas",
  126.   lastName: "Iosifelis"
  127. }, {
  128.   firstName: "George",
  129.   lastName: "Iosifelis"
  130. },{
  131.   firstName: "Andreas",
  132.   lastName: "Iosifelis"
  133. }, {
  134.   firstName: "George",
  135.   lastName: "Iosifelis"
  136. },{
  137.   firstName: "Andreas",
  138.   lastName: "Iosifelis"
  139. }, {
  140.   firstName: "George",
  141.   lastName: "Iosifelis"
  142. },{
  143.   firstName: "Andreas",
  144.   lastName: "Iosifelis"
  145. }, {
  146.   firstName: "George",
  147.   lastName: "Iosifelis"
  148. },{
  149.   firstName: "Andreas",
  150.   lastName: "Iosifelis"
  151. }, {
  152.   firstName: "George",
  153.   lastName: "Iosifelis"
  154. }]
  155.  
  156.  
  157. async function getUser(user) {
  158.   return {
  159.     ...user,
  160.     id: await getUserId()
  161.   }
  162. }
  163.  
  164.  
  165. async function getResult() {
  166.   const promises = users.map(getUser)
  167.   const result = await Promise.all(promises)
  168.  
  169.   console.log(result)
  170. }
  171.  
  172. getResult()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top