Questions tagged [setimmediate]

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 ...args 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!");
33 questions
0
votes
1 answer

What is the correct term to describe the moment after cessation of code execution?

In JavaScript one can cause code to be executed immediately after the current bit of code has finished executing a la setImmediate or setTimeout(..., 0). What is the correct term for referring to the gap in execution? I want to know because I am…
Jack Allan
  • 14,554
  • 11
  • 45
  • 57
-1
votes
1 answer

Node.js: http.request() triggers after setImmediate()

I'm new in Node, so the following code behavior is not clear to me: function step(iteration) { if (iteration === 10) return; process.nextTick(() => { step(iteration + 1); // Recursive call from nextTick handler. console.log(`nextTick…
Boolean_Type
  • 1,146
  • 3
  • 13
  • 40
-2
votes
1 answer

While running setTimeout (timeout of 0) and setImmediate together, Why values are changing for same program when we running it again and again

While running setTimeout and setImmediate together, Why values are changing for same program when we running it again and again. (setTimeout's timing is 0). setImmediate(() =>…
1 2
3