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.52 KB | None | 0 0
  1. function download(file){
  2.  
  3. return new Promise(resolve => {
  4. console.log(`started downloading ${file.name}`)
  5.  
  6. setTimeout(() => {
  7. console.log(`downloaded ${file.name} in ${file.downloadTime}ms`);
  8. resolve();
  9. },file.downloadTime);
  10. })
  11.  
  12. }
  13.  
  14. const file = new File('example',2000)
  15. download(file).then(_ => console.log('complete'))
  16.  
  17. // ----- output in console -----
  18. // started downloading example ...(immediately)
  19. // downloaded example in 2000ms ...(after 2s)
  20. // complete ...(after 2s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement