Registry / database / dtimer

dtimer

JSON →
library0.3.3jsnpmunverified

Distributed timer backed by Redis for clustered server environments. Version 0.3.3 (stable; low release cadence). Replaces unreliable setTimeout() with persistent timed events stored in Redis, supporting round-robin distribution across multiple listeners via pubsub. Requires Redis 2.6.0+ and promisified redis client (bluebird). Key differentiator: low-latency notification and retry mechanism via confirmation timeout.

npm install dtimer
INSTALL
IMPORT
SIG · DTIMER
D
dtimer
databasejavascriptv0.3.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

DTimer
import { DTimer } from 'dtimer'
const DTimer = require('dtimer')
ESM-only since v0.3; default export is DTimer constructor.
DTimer
const { DTimer } = require('dtimer')
CJS destructured require works as ESM default export is also exported as named.
DTimer
import DTimer from 'dtimer'
const DTimer = require('dtimer').default
Default import also valid; do NOT use .default in CJS.

Shows how to create a DTimer instance, listen for events, post an event with 5s delay, and confirm processing.

const Promise = require('bluebird'); const redis = require('redis'); Promise.promisifyAll(redis); const pub = redis.createClient(); const sub = redis.createClient(); const { DTimer } = require('dtimer'); const timer = new DTimer('my-node', pub, sub, { ns: 'app1' }); timer.on('event', (ev) => { console.log('Received event:', ev); timer.confirm(ev.id); }); timer.join() .then(() => timer.post({ id: 'evt1' }, 5000)) .then((evId) => console.log('Posted event:', evId)) .catch((err) => console.error(err));
Debug
Known issues
gotchaRedis client must be promisified before passing to DTimer. Failure leads to silent errors or crashes.
fix
Call Promise.promisifyAll(redis) before creating clients.
affects: >=0.1
deprecatedCallback style for join/leave/post/confirm is deprecated; use Promises.
fix
Omit callback argument and use .then() / async-await.
affects: >=0.3
gotcha'id', 'maxRetries', '_numRetries' are reserved property names in event objects. Using them for custom data causes conflicts.
fix
Nest user data under a property like 'data' to avoid collision.
affects: >=0.1
breakingReducing maxEvents during runtime can cause lost events if current subscription batch is larger.
fix
Set maxEvents before join() or leave() and rejoin.
affects: >=0.1
gotchaMust call confirm() within confTimeout to receive event; otherwise retries may exhaust and event is lost.
fix
Always call timer.confirm(ev.id) in event handler.
affects: >=0.1
Errors
Common errors & fixes
TypeError: Cannot read property 'id' of undefined
Event object is undefined because confirm() not called or timeout expired.
fix
Ensure confirm() is called within handler and confTimeout is sufficient.
Error: redis is not promisified
Missing Promise.promisifyAll(redis) before creating clients.
fix
Add: const Promise = require('bluebird'); Promise.promisifyAll(require('redis'));
UnhandledPromiseRejectionWarning: Error: TIMEOUT
Event confirmation not received within confTimeout, causing retry exhaustion.
fix
Check that confirm() is called and confTimeout is not too short.
TypeError: timer.join is not a function
Incorrect import: using default export without destructuring or wrong module resolution.
fix
Use: const { DTimer } = require('dtimer') or import DTimer from 'dtimer'.
Upgrade
Version history
0.3.3latest on npm
Audit
Dependencies
redisrequiredRedis client for pub/sub and storage; must be promisified externally
bluebirdoptionalUsed to promisify the redis module; not a direct dependency but required in user code
Agent activity
7 hits · last 30 days
node
6
Resources
packagedtimer
dtimer — npm install dtimer · libregistry