Releases: onury/tasktimer
Releases · onury/tasktimer
v4.0.0
A 2026 modernization of TaskTimer — ESM-only, zero-dependency, browser-safe, strongly typed — with some new sugar (lead, task.data, typed events, coded errors, silentErrors). The scheduling model is the same; the surface around it is cleaner and more honest. See the migration notes below.
Added
leadtask option — run a task once immediately when the timer starts (the leading edge), in addition to its normal tick schedule, instead of waiting a full interval. A futurestartDatestill defers it. Fixes #41.task.data— attach arbitrary user data to a task, available in the callback and event listeners.Taskis now generic (Task<TData>); type it viatimer.get<MyType>(id). Fixes the ergonomics behind #43.timer.tasks— a getter returning all tasks in insertion order (timer.tasks.map(t => t.id)for every id). Fixes #40.silentErrorstimer option (defaulttrue) — whenfalse, a task error with notaskErrorlistener is surfaced (re-thrown on the next turn) instead of swallowed; the timer keeps running either way.TaskTimerError+ErrorCode— every error the library throws is now aTaskTimerErrorcarrying a stable, machine-readablecode(and acause), so failures can be branched on without matching the message.
Changed
- Breaking — ESM-only (
"type": "module"); no CommonJS entry.import { TaskTimer } from 'tasktimer'. Still runs in the browser via native ESM / a bundler. See the ESM notice. - Breaking — minimum Node.js is now 22.
- Breaking — no more
TaskTimernamespace.Event,State,Task(and the newTaskTimerError,ErrorCode) are named exports:import { TaskTimer, Event, State } from 'tasktimer'.TaskTimer.Event.TICK→Event.TICK. - Breaking — event payload redesigned to
{ name, timer, task, error }(was{ name, source, data }). The related task is alwaysevent.taskand the timer alwaysevent.timer— consistently, including ontaskError. Listeners are now typed (you get anITaskTimerEvent, notany). - Breaking — task option
immediaterenamed todefer— it defers the callback to the next event-loop turn (viasetImmediate); the old name read as the opposite. - Breaking —
timer.get(id)returnsTask | undefined(was typedTask, returnednull), mirroringMap.get. - Zero runtime dependencies —
eventemitter3replaced by a small built-in, typedEventEmitter(sameon/once/off/emitsurface). - Precision now uses the monotonic
performance.now()in every environment (Node and browser), so browser precision is no longer subject to wall-clock drift. - Types compile against TypeScript 6 and ship with declaration maps.
Fixed
- Task
time.elapsedwas negative while a task was running (stopped - startedwithstoppedstill0); it now counts up live and freezes on completion, mirroring the timer'stime. Fixes #12. - Invalid option values (
NaN/Infinity) no longer slip through: aNaNinterval no longer busy-loops and aNaN/InfinitytickInterval/totalRunsno longer makes a task silently never run — they fall back to their defaults. - A task that throws every run now honors
totalRunsinstead of running forever — an errored run counts toward completion. - Calling
start()from within a tick no longer leaves a second tick chain running (double-speed ticks). - The browser fallback for
setImmediatedefers correctly viasetTimeout(…, 0).
Removed
- Breaking — the bundled UMD
<script>build (tasktimer.min.js). Bundle TaskTimer with your app (Vite, esbuild, Rollup, webpack …) for browser use.
Docs / Tooling
- New documentation site at onury.io/tasktimer; rewritten README and example-rich TSDoc across the public API.
- Build is a plain
tscemit tolib/. Adopted Biome (lint + format), Vitest (100% coverage, all four metrics), and Stryker mutation testing (100%); CI on GitHub Actions (Node 22, 24).
Migrating from 3.x
import TaskTimer from 'tasktimer'→import { TaskTimer } from 'tasktimer'; named exports forEvent/State/Task.TaskTimer.Event.TICK→Event.TICK;TaskTimer.State.RUNNING→State.RUNNING.- In event listeners:
event.data→event.task,event.source→event.timer(useevent.taskfor the task ontaskError). - Task option
immediate: true→defer: true. timer.get(id)now returnsundefined(notnull) when absent.- Errors thrown by the library are
TaskTimerError(stillinstanceof Error); branch onerr.codeif you handle them.
TaskTimer v3.0.0
An accurate timer utility for running periodic tasks on the given interval ticks or dates. (Node and Browser)
- See ChangeLog.
- See API Reference.
TaskTimer v2.0.1
An accurate timer utility for running periodic tasks on the given interval ticks or dates. (Node and Browser)
- See ChangeLog.
- See API Reference.
TaskTimer v2.0.0
An accurate timer utility for running periodic tasks on the given interval ticks or dates. (Node and Browser)
- See ChangeLog.
- See API Reference.
TaskTimer v1.0.0
A timer utility for running/scheduling periodic tasks on the given interval ticks. (Node and Browser)
See ChangeLog.