Event Loop
GitbookKb2021-01-11
📑 microtasks
Microtasks come solely from our code. They are usually created by promises
: an execution of .then/catch/finally
handler becomes a microtask. Microtasks are used “under the cover” of await
as well, as it’s another form of promise handling.
📑 macrotasks
- macrotask queue
- macrotask =? time slot
📑 event loop
- Dequeue and run the oldest task from the macrotask queue (e.g. “script”).
- Execute all microtasks: While the microtask queue is not empty: Dequeue and run the oldest microtask.
- Render changes if any.
- If the macrotask queue is empty, wait till a macrotask appears.
- Go to step 1.