heavy-computation-settimeout.js
✓ Published0🌍 Public
Aalessioalex
Last edited Nov 22, 2014
Created on Nov 22, 2014
This animation demonstrates how a long-running computation can be broken into chunks without freezing the event loop. The code repeatedly computes the sum of even numbers up to 199,999,999, processing one million numbers per iteration via a `setTimeout` callback to yield control. A separate `setInterval` logs "I'm alive!!" every 200 milliseconds, proving the process remains responsive. The script uses plain JavaScript timers and a recursive `getSum` function, with progress logged to the console and timing measured via `console.time` and `console.timeEnd`.
AI-generated description