Answers for "micro tasks in javascript"

1

javascript tasks and microtasks

In one go-around of the event loop (exactly one task), 
- Task will prioritised and finish first
- All microtasks currently in queue will be executed at the end of the task
- More tasks can be queued while the microtasks are being processed

Summary:
- Tasks execute in order, and the browser may render between them.
- Microtasks execute in order, and are executed: after every callback, as long as no other JavaScript is mid-execution. at the end of each task.

Examples:
Tasks: setTimeout, setInterval, setImmediate, requestAnimationFrame, I/O, UI rendering
Microtasks: process.nextTick, Promises, queueMicrotask, MutationObserver

Browsers Matter:
- Chrome usually gets this right
- Firefox and safari might queue things differently
- Edge, fuck edge, lmao.

*macrotask=task
Posted by: Guest on July-10-2021

Browse Popular Code Answers by Language