npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bazariodev/idle-watchdog

v0.2.0

Published

Dependency-free, re-armable one-shot inactivity timer with explicit activity reporting.

Readme

@bazariodev/idle-watchdog

A one-shot inactivity timer with no dependencies. Call arm() whenever there's activity; if idleMs passes without another arm(), your onIdle listeners run. What to do then is up to you.

Install

pnpm add @bazariodev/idle-watchdog

Usage

import { IdleWatchdog } from '@bazariodev/idle-watchdog';

const watchdog = new IdleWatchdog({ idleMs: 30_000 });
watchdog.onIdle(() => console.log('No messages for 30 seconds.'));

// `socket` is yours. Each message starts a fresh 30-second window.
const onMessage = () => watchdog.arm();
socket.addEventListener('message', onMessage);
watchdog.arm(); // start the first window now

To pause, call watchdog.cancel(); the next arm() starts a new window. To remove a single onIdle listener, call the function onIdle returns.

When you're done, remove your own activity listener and stop the watchdog:

socket.removeEventListener('message', onMessage);
watchdog.stop(); // or watchdog[Symbol.dispose]()

stop() disarms the watchdog and removes every onIdle listener for good. It doesn't touch your socket listener, which is why the example removes it first.

API

new IdleWatchdog({ idleMs, scheduler?, logger? }) creates a watchdog that isn't armed yet. idleMs is an integer from 1 to 2_147_483_647 milliseconds (about 24.85 days), or a function returning one. Fixed values are checked at construction. A function is called without a receiver once per arm() and its result is checked before scheduling. Invalid values throw RangeError; a throwing function propagates its error. The failed arm leaves no timer of its own. Durations are never clamped or rounded. Injecting a scheduler does not change the allowed range.

For optional jitter, inject idleMs: createJitter({ minMs: 40_000, maxMs: 60_000 }) from @bazariodev/coordination. The watchdog remains dependency-free and owns only the timer, not the random policy.

| Method | Behavior | | --- | --- | | arm() | Start a fresh inactivity window from now, replacing any pending window. | | cancel() | Disarm the timeout without removing listeners. Restartable and idempotent. | | onIdle(listener) | Subscribe and return an idempotent unsubscribe function. | | stop() / [Symbol.dispose]() | Disarm, clear listeners, and make every later call do nothing. |

  • Expiry fires once per arm(). The watchdog disarms before notifying, so a listener may call arm() to start the next window.
  • A timer from a cancelled or replaced window never reaches the listeners.
  • Listeners run synchronously, in registration order. Adding or removing listeners during a notification affects the next one; stop() also skips the remaining listeners of the current one.
  • Registering the same function twice creates one subscription. Either returned unsubscribe function removes it, and neither removes a later registration of that function.
  • A listener that throws is reported to logger.error, and the other listeners still run. Asynchronous failures inside listeners are yours to handle.

Scheduling

The default scheduler wraps the platform setTimeout and clearTimeout. Timers can fire late (busy event loops, background-tab throttling, and sleep all delay them), so this isn't a precise clock or a sleep detector. Pick limits stricter than the allowed range if your protocol needs them.

Inject a scheduler for tests or other runtimes:

type TimeoutScheduler = Readonly<{
  setTimeout: (callback: () => void, delayMs: number) => unknown;
  clearTimeout: (handle: unknown) => void;
}>;

Scheduler methods must not throw, and callbacks must run asynchronously, as platform timers do. Handles are opaque. logger is optional, needs only error(message, metadata?), and must not throw; it defaults to a no-op.

Composition

The watchdog doesn't inspect traffic, send pings, close connections, or reconnect. For connection liveness, use @bazariodev/keepalive, which builds on this package. Stop each watchdog when its owner is done with it.

The package has no dependency on FSM, Keepalive, Transport, or React. It ships ESM and CommonJS with TypeScript declarations.

License

MIT