Skip to content

Instantly share code, notes, and snippets.

@timkg
Created November 8, 2012 17:37
Show Gist options
  • Save timkg/4040283 to your computer and use it in GitHub Desktop.
Save timkg/4040283 to your computer and use it in GitHub Desktop.
Async function calls (like timer or event callbacks) are not executed from the current call stack, but pushed to the end of the queue, creating their own new call stack.
function stuff() {
var start = new Date();
// notice how 'stuff' is in the the call stack
debugger;
setTimeout(function timeout() {
var end = new Date()
, diff = end - start;
// notice how 'stuff' is NOT in the call stack
debugger;
console.log( diff + 'ms have passed' );
}, 500);
while( new Date() - 1000 < start ) {}
}
stuff();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment