Skip to content

Instantly share code, notes, and snippets.

@ackuser
Last active January 3, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ackuser/7ef5a071200fae517638 to your computer and use it in GitHub Desktop.
Save ackuser/7ef5a071200fae517638 to your computer and use it in GitHub Desktop.
// Difference between setTimeout, setImmediate and process.nextTick
var emitter = new require('events').EventEmitter();
setTimeout(function() {
console.log('TIMEOUT 1');
}, 0);
setImmediate(function() {
console.log("IMMEDIATE 1");
});
process.nextTick(function() {
console.log("NEXTTICK 1");
});
setTimeout(function() {
setTimeout(function() {
console.log('TIMEOUT 2')
}, 0);
setImmediate(function() {
console.log('IMMEDIATE 2')
});
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment