and you just need to execute it in the next tick (iteration of the event loop) instead.
I consider myself pretty well versed in javascript however I can not imagine what you mean with this. How would "execute it in the next tick" look in code?
setImmediate sometimes, you run into a max callstack issue for function calls if you don't ensure that the next call comes on the next tick. This is especially important for recursive functions or looping functions that might call itself again.
I actually just wrote a function with setImmediate today.
It’s a function you call to subscribe to an event emitter. The function returns a key that you can save for later. But I also have some cached values that I want to call the subscription callback with immediately. How do I first return the key, let the subscriber finish setting everything up and only then call the callback?
Answer: use setImmediate to call the callback on the next tick, i.e. when the subscriber is finished.
12
u/ThatBriandude May 28 '19 edited May 28 '19
I consider myself pretty well versed in javascript however I can not imagine what you mean with this. How would "execute it in the next tick" look in code?