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?

Community
  • 1
  • 1
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
  • You could also utilize the [`MutationObserver` API](https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/) in the browser. –  Jul 21 '16 at 13:10

1 Answers1

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.

Eric Shepherd
  • 186
  • 1
  • 5