2

There are micro- and macro- task queues in the JavaScript runtime.

setTimeout uses the macrotask queue.

setImmediate in IE11 presumably uses the microtask queue?

process.nextTick uses the microtask queue.

But setImmediate is not implemented in any other browser (and won't be AFAIK).

And process.nextTick is Node only.

Promises use the micro task queue. Could Promise therefore be leveraged to provide setImmediate like functionality in non IE browsers?

1
  • You could also utilize the MutationObserver API in the browser. Commented Jul 21, 2016 at 13:10

1 Answer 1

2

Three years later, of course, but we do have an answer for this now: the window.queueMicrotask() method has been added to allow adding a callback to the JavaScript runtime's microtask queue. I'm currently working on fleshing out a microtask guide on MDN Web Docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.