Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. console.clear();
  2. console.log("a");
  3. setTimeout(function(){console.log("b");},1000);
  4. console.log("c");
  5. setTimeout(function(){console.log("d");},0);
  6.  
  7. function downloadFile(filePath, callback)
  8. {
  9. blah.downloadFile(filePath);
  10. callback();
  11. }
  12.  
  13. //Let's say this code is running in tick 1
  14. fs.readFile("/home/barney/colors.txt", function (error, data) {
  15. //The code inside this callback function will absolutely NOT run in tick 1
  16. //It will run in some tick >= 2
  17. });
  18. //This code will absolutely also run in tick 1
  19. //HOWEVER, typically there's not much else to do here,
  20. //so at some point soon after queueing up some async IO, this tick
  21. //will have nothing useful to do so it will just end because the IO result
  22. //is necessary before anything useful can be done
  23.  
  24. console.clear(); //exec sync
  25. console.log("a"); //exec sync
  26. setTimeout( //schedule inAWhile to be executed at now +1 s
  27. function inAWhile(){
  28. console.log("b");
  29. },1000);
  30. console.log("c"); //exec sync
  31. setTimeout(
  32. function justNow(){ //schedule justNow to be executed just now
  33. console.log("d");
  34. },0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement