Promise.prototype .then has microtask semantics. This means that it must wait for the synchronous code to execute, but not to run the asynchronous code - browsers will probably prefer that all JS start before the DOM updates are executed.
As a rule, microtask means that it needs to wait for another JS to start, and then it can work before it brings control to a non-JS code.
setTimeout has setTimeout semantics. It works as part of the DOM API, and when the callback works, code other than js is already able to run. Browsers already run their own code when it runs, so they also handle events and DOM updates.
Usually a macro means that he needs to wait for the launch of all the other JSs, as well as for the βtick of the loopβ, that is: events to run.
This is also the difference between setImmediate and nextTick in NodeJS .
To answer your question directly: no. . It is not possible to force the browser to run DOM updates in the microtype update - while it is not forbidden for it, it will be a "bad manners".
For lengthy processor-bound operations - can I offer Web Workers instead?
source share