| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is a part of the Node3D project.
npm install @node-3d/uv-loop@node-3d/uv-loop is a deliberately small native addon that exposes a hot libuv idle loop primitive. It starts one shared unref'd idle pump when imported, then lets TypeScript register one-shot and looping callbacks on top of that single native pump.
It is intended for render loops and other latency-sensitive work where recursive setImmediate or timer scheduling can produce visibly uneven frame pacing. It does not implement throttling; callers that need slower updates can throttle downstream through vsync, timers, or their own timing conditionals. It does not know about GLFW, WebGL, Three.js, or Node3D frame policies.
The API mirrors Node's timer handle style:
import { clearIdleLoop, setIdleLoop } from '@node-3d/uv-loop';
const loop = setIdleLoop(() => {
render();
if (done) {
clearIdleLoop(loop);
}
});
loop.unref();For a one-shot idle callback:
import { setIdle } from '@node-3d/uv-loop';
setIdle(() => {
updateOnce();
});Handles are ref'd by default, like Node.js timer handles. Use unref() when idle work should not keep the process alive, and ref() to opt back in.
import { clearIdleLoop, setIdleLoop } from '@node-3d/uv-loop';
const loop = setIdleLoop(() => {
render();
if (done) {
clearIdleLoop(loop);
}
});
loop.unref();
loop.ref();
loop.hasRef();Idle handles expose Node timer-style lifecycle methods:
The native addon still uses one shared libuv idle pump internally. Per-handle ref state is tracked in TypeScript and translated to the shared native pump.
Set NODE_3D_UV_LOOP_STUB=1 or pass --node-3d-uv-loop-stub as an application argument to load a JavaScript stub instead of the native binary. The stub uses recursive setImmediate scheduling and implements the same public API. This is useful for CI, unsupported runtime experiments, or comparing behavior without the native libuv path.
Run the benchmark from this package:
node examples/benchmark.ts
node examples/benchmark.ts --seconds=10Release archives are built by this repository's public GitHub Actions workflows.
Attestations: https://github.com/node-3d/uv-loop/attestations
To verify a downloaded archive:
gh release download <tag> -R node-3d/uv-loop -p <platform>.gz
gh attestation verify <platform>.gz -R node-3d/uv-loopPrebuilt addon binaries are provided for Windows x64/ARM64, Linux x64/ARM64, and macOS x64/ARM64. Because this addon calls libuv directly, release binaries are split by Node.js major version. Install chooses the binary tag from the runtime Node.js version:
There is no compilation step during the npm install command when a matching prebuilt archive is available.
This package uses napi_get_uv_event_loop() and direct libuv APIs from <uv.h>. Node-API itself is ABI-stable, but Node.js does not guarantee libuv ABI stability across Node.js major versions. This package intentionally contains that risk in one small optional scheduling layer.
When the runtime Node.js major does not have an exact binary line, install logs a warning and falls back to the nearest configured binary line described above.
| Back | FazBrowse Home | New Git URL |