Skip to content

Instantly share code, notes, and snippets.

@JeOam
Created October 15, 2017 07:34
Show Gist options
  • Save JeOam/c84f0b421ddf731498ec55fb040b4078 to your computer and use it in GitHub Desktop.
Save JeOam/c84f0b421ddf731498ec55fb040b4078 to your computer and use it in GitHub Desktop.
macrotask vs microtask

一个事件循环(EventLoop)中会有一个正在执行的任务(Task),而这个任务就是从 macrotask 队列中来的。在whatwg规范中有 queue 就是任务队列。当这个 macrotask 执行结束后所有可用的 microtask 将会在同一个事件循环中执行,当这些 microtask 执行结束后还能继续添加 microtask 一直到真个 microtask 队列执行结束。

  • macrotasks: setTimeout setInterval setImmediate I/O UI渲染
  • microtasks: Promise process.nextTick Object.observe MutationObserver

via click

@JeOam
Copy link
Author

JeOam commented Oct 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment