#settimeout #setinterval #event_loop #requestAnimationFrame
Why setTimeout is Inaccurate? β
setTimeout and setInterval in JavaScript are based on the event loop and task queue. Their execution time may vary due to several factors:
Event Loop Mechanism:
JavaScript executes code within a single event loop. If earlier tasks take a long time or the task queue is busy, the timer callback will be delayed.
Task Queue Priority:
The priority of tasks in the task queue varies. User interaction events or rendering updates might have higher priority than setTimeout and setInterval, delaying their execution.
JavaScript Engine Limitations:
The JS engine normally imposes a minimum delay; for example, nested setTimeout calls usually have a minimum delay of 4 milliseconds.
System Performance and Load:
System performance and current load can also affect timer accuracy. High system load can further delay task execution.
β Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
setTimeout in Angular#angular #setTimeout
What setTimeout Really Does in Angular
In JavaScript, setTimeout queues a task on the macrotask queue to be run after the current call stack clears. In a normal JS app, this is predictable.
But Angular isnβt just JavaScript β it uses Zone.js under the hood.
Zone.js monkey-patches setTimeout so Angular can trigger change detection after async operations.
Every time setTimeout fires, Angular knows something changed. So it runs its entire component tree check cycle.
β Article Link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
2π4β€1