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/keepalive

v0.2.0

Published

Generic connection liveness with abortable probes and idle deadlines.

Readme

@bazariodev/keepalive

Keepalive runs one abortable liveness probe after a quiet period. It owns idle and response timers. The connection owner decides what to do after failure.

Install

pnpm add @bazariodev/keepalive

Keepalive has no peer dependencies. It installs @bazariodev/idle-watchdog as a runtime dependency.

Usage

import { Keepalive } from '@bazariodev/keepalive';

const keepalive = new Keepalive({
  idleMs: 30_000,
  deadlineMs: 5_000,
  probe: async (signal) => {
    await checkPeer(signal);
  },
});

keepalive.onFail((failure) => connectionOwner.retire(failure));
keepalive.start();

checkPeer is an application function. It must reject when it cannot confirm a response. Call activity() for validated incoming traffic. Stop the monitor when its connection ends. Create a new instance for each connection.

Behavior

  • Construction is inert. start() arms the first idle timer.
  • activity() resets the idle timer only while started and no probe is active.
  • probeNow() starts a probe at once. Repeated calls coalesce while a probe is active.
  • The probe receives a fresh AbortSignal. The fixed deadlineMs is not extended by activity.
  • Fulfillment resumes idle monitoring. Rejection, timeout, or an invalid duration draw stops the instance and publishes one failure.
  • stop() is terminal and idempotent. It cancels timers and aborts active work. Late promise results have no effect.
  • Keepalive does not parse packets, create IDs, answer peer pings, retry, or replace connections. The probe owns its request format and response matching.
  • A probe can use RpcClient.probe(). A matched server error proves a round trip, but it does not prove that the application operation succeeded.

API

| Option | Default | Purpose | | --- | --- | --- | | probe | required | (signal: AbortSignal) => Promise<void>. Fulfill only after the required response arrives. | | idleMs | required | Positive integer milliseconds or a function that returns one duration for each idle window. | | deadlineMs | required | Fixed positive integer response duration in milliseconds. | | scheduler | platform timers | Optional KeepaliveScheduler with opaque timer handles. | | logger | no-op | Optional non-throwing error logger. |

| Method | Purpose | | --- | --- | | start() | Start once. Later calls do nothing. | | activity() | Reset the idle timer when no probe is active. | | probeNow() | Start a probe now when started and idle. | | onFail(listener) | Observe the terminal { type: 'timeout' } or { type: 'error', error } result. | | stop() / [Symbol.dispose]() | Stop permanently and release owned work. |

Here, connectionOwner is an application-supplied helper that retires the current attempt. Durations must be integer milliseconds from 1 through 2,147,483,647. Scheduler methods and returned unsubscribe functions must not throw. Failure listeners are isolated; one listener error does not stop delivery to later listeners.

Errors

Invalid options throw TypeError or RangeError during construction. A probe rejection or invalid duration draw produces { type: 'error', error }. A missed deadline produces { type: 'timeout' }. Keepalive reports failure once and does not choose a recovery action.

TypeScript

The package ships ESM and CommonJS declarations. Include DOM or WebWorker platform types. Public types include KeepaliveOptions, KeepaliveProbe, KeepaliveFailure, KeepaliveScheduler, KeepaliveLogger, and Unsubscribe.

License

MIT. See LICENSE.