Last active
December 24, 2018 18:55
-
-
Save rajikaimal/f4a8c4f6ea6e154aea3bddc125d4156e to your computer and use it in GitHub Desktop.
setImmediate vs setTimeout vs process.nextTick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
fs.readFile(__filename, () => { | |
setTimeout(() => { | |
console.log('SetTimeout callback'); | |
}, 0); | |
setImmediate(() => { | |
console.log('SetImmediate callback'); | |
}); | |
process.nextTick(() => { | |
console.log('NextTick'); | |
}); | |
}); | |
// Output: | |
// NextTick | |
// SetImmediate callback | |
// SetTimeout callback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment