Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.clear();
- console.log("a");
- setTimeout(function(){console.log("b");},1000);
- console.log("c");
- setTimeout(function(){console.log("d");},0);
- function downloadFile(filePath, callback)
- {
- blah.downloadFile(filePath);
- callback();
- }
- //Let's say this code is running in tick 1
- fs.readFile("/home/barney/colors.txt", function (error, data) {
- //The code inside this callback function will absolutely NOT run in tick 1
- //It will run in some tick >= 2
- });
- //This code will absolutely also run in tick 1
- //HOWEVER, typically there's not much else to do here,
- //so at some point soon after queueing up some async IO, this tick
- //will have nothing useful to do so it will just end because the IO result
- //is necessary before anything useful can be done
- console.clear(); //exec sync
- console.log("a"); //exec sync
- setTimeout( //schedule inAWhile to be executed at now +1 s
- function inAWhile(){
- console.log("b");
- },1000);
- console.log("c"); //exec sync
- setTimeout(
- function justNow(){ //schedule justNow to be executed just now
- console.log("d");
- },0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement