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?
My favorite way to run code asynchronously as tightly as possible (absent node's nextTick stuff) is to use Promise.resolve().then(...).
That will schedule a microtask, which may end up running after other scheduled microtask, but still long before anything else. It's so fast it can often be "too fast", particularly if you're hoping the browser will redraw anything before calling your code again, the way a setTimeout(... ,0) would.
There are other approaches, like mildly abusing the postMessage API, but nothing as straightforward as an immediate promise.
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?