Advertisement
Guest User

Untitled

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