Guest User

Untitled

a guest
Oct 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. // What order will the console logs occur?
  2.  
  3. function foo(resolve, reject){
  4. console.log('foo starting');
  5. for(i = 0; i<1000000000; i++){
  6. if ((i % 100000000) == 0)
  7. console.log('+');
  8. }
  9.  
  10. console.log('foo spinning done');
  11.  
  12. setTimeout(() => {
  13. console.log('foo timeout complete');
  14. resolve(29);
  15. console.log('foo back from resolve'); // << @wiz update
  16.  
  17. }, 2500);
  18. console.log('foo returning');
  19. }
  20.  
  21. console.log('creating promise');
  22. const promise = new Promise(foo);
  23. console.log('back from promise land');
  24.  
  25. promise.then((value) => {
  26. console.log('then called :',value);
  27. });
  28. console.log('all done');
Add Comment
Please, Sign In to add comment