See the power of stackful coroutines in action!
âś… Animation stays smooth!
⚠️ UI will freeze!
The heavy computation suspends periodically, allowing the browser to:
The computation runs in one continuous block, causing:
⚖️ 100% Fair Comparison: Both buttons run the EXACT SAME heavy computation—millions of trigonometric and exponential calculations simulating image processing operations. The ONLY difference is one line of code: ctx.Suspend(). There are no artificial delays or tricks! The freeze happens naturally because JavaScript/WebAssembly runs on a single-threaded event loop.
The Computation: Each iteration processes a virtual 1000Ă—1000
pixel image with 500 operations per iteration—simulating filters, edge detection,
and color transformations. You can verify the code yourself in
particle_simulation.cpp: both versions call the exact same
heavy_computation_step() function.
The Magic: The ctx.Suspend() call yields control back to the browser, allowing it to render frames and handle events. This is the power of stackful coroutines—you get cooperative multitasking without callbacks or promise chains!