Registry / http-networking / retimer

retimer

JSON →
library0.1.0.9jsnpmunverified

Retimer is a JavaScript library providing a reschedulable alternative to Node.js's native `setTimeout`. It is specifically designed for scenarios requiring frequent timer rescheduling, such as managing keep-alive functionality across numerous client connections or sockets, where repeatedly clearing and setting `setTimeout` can become a performance bottleneck due to Node.js's internal timer linked list management. The library works by allowing old timers to run out naturally while scheduling new ones, optimizing performance when rescheduling a timeout *after* its original duration. The current stable version is 4.0.0, which notably introduced TypeScript types and support for `worker-timers`. While release cadence isn't strictly defined, major versions appear every few years, indicating a mature and stable project. Its key differentiator is the performance optimization for 'reschedule after' scenarios, aiming for better efficiency than naive `clearTimeout`/`setTimeout` cycles.

npm install retimer
INSTALL
IMPORT
SIG · RETIMER
R
retimer
http-networkingjavascriptv0.1.0.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

retimer
import retimer from 'retimer';
import { retimer } from 'retimer';
The `retimer` function is the default export since v4.0.0, which added TypeScript types.
Retimer
import retimer, { Retimer } from 'retimer';
While `retimer` is the default function to create a timer, the `Retimer` type can be imported for TypeScript type hinting.
retimer
const retimer = require('retimer');
CommonJS `require` remains supported across all versions for Node.js environments.

Demonstrates initializing a retimer, rescheduling it, and finally clearing it, showcasing the basic API flow for managing reschedulable timeouts.

import retimer from 'retimer'; function setupTimer(initialTimeoutMs: number) { const timerCallback = () => { console.log('Timer executed after reschedule.'); // In a real application, you might re-evaluate what to do next // or simply let the timer be cleared if it's a one-off. }; const timer = retimer(timerCallback, initialTimeoutMs); console.log(`Initial timer set for ${initialTimeoutMs}ms.`); setTimeout(() => { const newTimeoutMs = 50; timer.reschedule(newTimeoutMs); console.log(`Timer rescheduled for ${newTimeoutMs}ms.`); setTimeout(() => { console.log('Clearing timer.'); timer.clear(); }, newTimeoutMs + 10); // Clear after the rescheduled timeout plus a small buffer }, initialTimeoutMs / 2); // Reschedule halfway through original timeout } // Example usage: setupTimer(100);
Debug
Known issues
breakingVersion 4.0.0 introduced TypeScript types and worker-timers support. While primarily an enhancement, direct usage of internal properties or assumptions about untyped behavior might be affected. ESM import patterns are now the idiomatic choice for TypeScript users.
fix
Review existing code for explicit type assertions or reliance on non-public APIs. Adopt ESM import syntax (`import retimer from 'retimer'`) for new TypeScript projects.
affects: >=4.0.0
gotchaRetimer provides performance benefits primarily when rescheduling a timeout to occur *after* its original duration. If the new timeout is *before* the original one, `retimer` will internally clear the previous timer and set a new one, similar to native `clearTimeout`/`setTimeout`, thus offering no performance gain in that specific scenario.
fix
Be aware of the rescheduling direction. For scenarios where timeouts are consistently shortened, `retimer` might not yield expected performance improvements, and a careful analysis of timer patterns is recommended.
affects: >=1.0.0
breakingVersion 2.0.0 increased the minimum required Node.js version to 6.
fix
Ensure your Node.js environment is at least version 6.x or newer. Modern applications should target much newer LTS versions of Node.js.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: retimer is not a function
Attempting to call `retimer` when it hasn't been correctly imported or required.
fix
Ensure correct import statement for ESM (`import retimer from 'retimer';`) or CommonJS (`const retimer = require('retimer');`). For TypeScript, also ensure your `tsconfig.json` `moduleResolution` allows proper module resolution.
Error: this should never get called!
A `retimer` callback function was executed, implying `timer.clear()` or `timer.reschedule()` did not prevent its execution as intended.
fix
Verify the logic and timing of `timer.clear()` and `timer.reschedule()`. Ensure they are called with sufficient time before the scheduled execution of the timer's callback. Remember `reschedule` only takes effect if the new timeout is valid.
Upgrade
Version history
0.1.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
retimer — npm install retimer · libregistry