Event Loop
Callback-based animation frame request
nx.js runs an event loop driven by libuv (the same library that powers Node.js), which services timers, async I/O, and the render loop.
To hook into each frame of the event loop in nx.js, use the
requestAnimationFrame()
function. This allows your app to update its state at a fixed frame rate (60 FPS).
The familiar timer functions (setTimeout(),
setInterval(),
queueMicrotask(),
and Promises) are also available.
Example
const ctx = screen.getContext('2d');
ctx.fillStyle = 'white';
ctx.font = '40px sans-serif';
// The `update()` function is called for every frame of the event loop
function update() {
requestAnimationFrame(update);
ctx.clearRect(0, 0, screen.width, screen.height);
ctx.fillText(new Date().toISOString(), 10, 50);
}
update();