TaskTimer
An accurate timer utility for running periodic tasks on the given interval ticks or dates — one timer, many tasks, with drift correction.
import { TaskTimer, Event } from 'tasktimer';
const timer = new TaskTimer(1000); // 1s base interval
timer.add(task => console.log(`run #${task.currentRuns}`));
// listen for lifecycle events — every listener gets a typed eventtimer.on(Event.TICK, () => console.log(`tick ${timer.tickCount}`));timer.on(Event.TASK, event => console.log(`ran: ${event.task.id}`));
timer.start();Accurate
Drift between ticks is auto-corrected against task/CPU load and clock drift — using the monotonic performance.now() in both Node and the browser.
Many Tasks, One Timer
Run and schedule any number of tasks — each on its own interval, delay, run limit, or date window — from a single instance.
Sync or Async
Return a Promise or call done(). Limit runs, listen for events, pause and resume at any time.
ESM, Zero-Dependency
An ESM-only module with no runtime dependencies, written in TypeScript with complete type definitions.
© 2026, @onury • MIT License