Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. function parallelDownload(files){
  2. const downloadPromises = files.map(file => download(file));
  3. return Promise.all(downloadPromises);
  4. }
  5.  
  6. parallelDownload(mockFiles)
  7. .then(_ => console.log('files were downloaded in parallel mode'))
  8.  
  9. // ----- output in console -----
  10.  
  11. // started downloading file 1 ...(immediately)
  12. // started downloading file 2 ...(immediately)
  13. // started downloading file 3 ...(immediately)
  14.  
  15. // downloaded file 1 in 2000ms ...(after 2s)
  16.  
  17. // downloaded file 3 in 3000ms ...(after 3s)
  18.  
  19. // downloaded file 2 in 4000ms ...(after 4s)
  20.  
  21. // files were downloaded in parallel mode ...(after 4s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement