Node JS's SetImmediate schedules the "immediate" execution of the callback after I/O events' callbacks and before timers created using setTimeout() and setInterval() are triggered. Returns an Immediate for use with clearImmediate().
setImmediate(callback[, ...args])
callback
The function to call at the end of this turn of the Node.js Event Loop
...arg
s Optional arguments to pass when the callback
is called.
When multiple calls to setImmediate()
are made, the callback
functions are queued for execution in the order in which they are created. The entire callback queue is processed every event loop iteration. If an immediate timer is queued from inside an executing callback, that timer will not be triggered until the next event loop iteration.
If callback
is not a function, a TypeError will be thrown.
Example of setImmediate
This will output hello \n world!
var saywhat = 'hello';
setImmediate(function(value) {
console.log(saywhat);
console.log(value);
}, "world!");