I have looked into web and similar threads in stackoverflow
, but i am really not understanding the difference between them and the scenarios where one would be useful compared to other.
Let me put my understanding
in code wise.
function sum(a, b, cb){
setImmediate(function(){
cb(a + b)
});
}
sum(10, 10, console.log);
console.log("Done")
function anotherSum(a,b,cb){
process.nextTick(function(){
cb(a + b);
});
}
anotherSum(2, 3, console.log);
console.log("End")
Here using the process.nextTick
/setImmediate
, we are actually delaying the callback
execution.
Output:
Done End 5 20
Both are delaying the execution of the callback
, can anyone tell me the exact difference
with some example
.