diff --git a/README.md b/README.md index 924a02f7..58271fc4 100644 --- a/README.md +++ b/README.md @@ -425,6 +425,21 @@ The Event Loop is a critical part of JavaScript's concurrency model, ensuring no **[⬆ Back to Top](#table-of-contents)** +### Event Loop demo (interactive) + +There is a small interactive demo included in this repository to visualize microtasks vs macrotasks ordering in the browser. + +- File: `event-loop-demo.html` +- How to open: double-click the file in your file manager or open it in your browser. From the repo root you can also run a simple static server, for example with Python 3: + +```powershell +# from repository root +python -m http.server 8080; # then open http://localhost:8080/event-loop-demo.html +``` + +The demo logs messages to the page and to the browser console showing the expected ordering between synchronous code, microtasks (Promises / async / MutationObserver) and macrotasks (setTimeout). + + --- ## 10. setTimeout, setInterval and requestAnimationFrame diff --git a/event-loop-demo.html b/event-loop-demo.html new file mode 100644 index 00000000..3123f353 --- /dev/null +++ b/event-loop-demo.html @@ -0,0 +1,195 @@ + + + + + + Event Loop: Message Queue and Microtasks Demo + + + +

Event Loop: Message Queue and Microtasks Demo

+

This demo illustrates how the Event Loop processes tasks from the Message Queue (macrotasks) and Microtask Queue. The Message Queue handles setTimeout callbacks and DOM events, while the Microtask Queue processes Promises and async/await operations with higher priority.

+ +
+ + + + +
+ +
+ + + + + + +