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
1
vote
2 answers

Why am I getting the error clearImmediate is not defined?

i am trying to make an infinitive loop that stops when the video is uploaded. The function works fine, however to stop the loop does not seem to work. The error I get is: clearImmediate is not defined this is the loop i am trying to…
Ewald Bos
  • 1,560
  • 1
  • 20
  • 33
1
vote
0 answers

Try to find node express blocked cpu code, and want to make express handlers async for stack trace

I have node10 express app, something like: const app = express(); app.use(function(req, res, next) { ..} app.use( bodyParser.text({ limit: '1mb', type: '*/*', }) ); more of those.. app.post('myApiName', [(req, res, next) => {..}, (req,…
FMoran
  • 51
  • 1
  • 4
0
votes
0 answers

How does callback of setImmediate executed before setTimeout() when scheduled in Poll phase?

These are quote from Nodejs documentation and blogs. If an immediate timer is queued from inside an executing callback, that timer will not be triggered until the next event loop iteration. setImmediate() will always be executed before any timers…
user2734550
  • 952
  • 1
  • 12
  • 35
0
votes
0 answers

setImmediate() documentation issue (hopefully)

found this while going thru the documentation nodejs.org - guide url (left side) nodejs.dev - url from the guides section (Introduction to Node.js) (right side) red marked line (left side) - green marked line (right side) are contradicting in their…
0
votes
1 answer

Uncaught (in promise) ReferenceError: setImmediate is not defined

I want to get my id with setImmediate and copy it with CopyToClipboard. I guess I'm pulling the value as blank on the page because the setImmediate function has been removed. What can I use instead of this function and get my id value? This is the…
idil
  • 69
  • 6
0
votes
0 answers

callback added by Process.nextTick() and setImmediate() not executed

My electron application has a problem.Sometimes those callback didn't print at dev tool's console while setTimeout works well. setImmediate(()=>{ console.log("setImmediate") }) process.nextTick(()=>{ console.log("nextTick") }) I read…
KayWang
  • 71
  • 6
0
votes
1 answer

nodejs aync function taking more time when I replace function call with another function which is similar

Can someone explain to me why there is less time required when I run below code with: for2=longTsk() -- approx 2500ms every time and for for2=longTsk3() -- approx 3000ms every time The plain for loop in both the functions requires approx 1500ms…
0
votes
1 answer

How the read time is calculated for a passage of texts in android studio app. (Using java) same as medium article

How the read time is calculated for a passage of text in android studio app. (Using java) same as medium article. Sample image shown as below. I have used textview to show the texts.
sejn
  • 2,040
  • 6
  • 28
  • 82
0
votes
0 answers

Is setImmediate a good solution for testing using jest after async setState updates?

I've been using the following pattern to test conditions after state updates in my components using react. await expect(new Promise((resolve) => { let intervalId = setInterval(() => { component.update(); if (myCondition) { …
Adam Thompson
  • 3,278
  • 3
  • 22
  • 37
0
votes
0 answers

How does Node.js' event loop treat these two pieces of code?

I'm trying to understand Nodejs's official explanation about Event Loop. They have explained an example for Timers phase, but I'm unable to match it with their explanation about setTimeout and setImmediate. Could you please explain, in detail, all…
Mahdi
  • 1,089
  • 1
  • 14
  • 27
0
votes
1 answer

Can anybody explain the output of setImmediate and setTimeout in this code?

What would be the output of setImmediate and setTimeout in the following code: console.log("11111"); setImmediate(function A(){ console.log("2222"); }); console.log("3333"); setTimeout(function B(){ …
0
votes
1 answer

recursion with setImmediate()

I have the following recursive function: function explore(v, componentN) { return function () { nodes[v].visited = true; nodes[v].componentNumber = componentN; preVisit(v); adjList[v].forEach((item) => { …
turisap
  • 231
  • 4
  • 13
0
votes
3 answers

why this setImmediate is called before file read callback?

Have look on these lines of code function someAsyncOperation () { console.log("inside someAsyncOperation"); var startCallback = Date.now(); // do something that will take 10ms... while (Date.now() - startCallback <= 100) { ; // do…
nurulnabi
  • 459
  • 3
  • 11
0
votes
1 answer

nodejs: When should I use `setImmediate(cb)` vs `cb()`?

When reading on The Callback Hell , I came across two different ways of calling a callback function in the exact same example linked above (last example in the linked section): cb(); and then setImmediate(cb); for seemingly exactly the same…
SCBuergel
  • 1,613
  • 16
  • 26
0
votes
2 answers

NodeJS SetImmediate and callback function

The code below works - but after i updated NODEJS from 4.. to 6.9.1 it suddently throws an error (for each call)...meaning it executes all recursive calls perfectly and afterwards tells me like 20 times the error message below... "callback"…
PabloDK
  • 2,181
  • 2
  • 19
  • 42