programming:

Playing with Node.js Event Loop

setImmediate/clearImmediate - will execute code at the end of the current event loop cycle process.nextTick - used to schedule a callback function to be invoked in the next iteration of the Event Loop function cb(msg){ console.log(msg); } setImmediate(cb, 'setImmediate'); process.nextTick(cb, 'process.nextTick: 1'); process.nextTick(cb, 'process.nextTick: 2'); process.nextTick(cb, 'process.nextTick: 3'); console.log('Processed in the first iteration'); process.nextTick(cb, 'process.nextTick: 4'); process.nextTick(cb, 'process.nextTick: 5'); Output: Processed in the first iteration process.nextTick: 1 process.nextTick: 2 process.nextTick: 3 process.

by lek tin in "programming" access_time 1-min read