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

async-tracer-ts

v1.0.0

Published

A lightweight, framework-agnostic TypeScript utility to trace async function lifecycle and performance.

Readme

async-tracer-ts

A lightweight, framework-agnostic TypeScript utility that wraps any async function to trace its lifecycle and measure performance — with production-grade retry, timeout, and abort support.

Zero dependencies · Dual ESM/CJS · Strict TypeScript · 100% tested


Features

| Feature | Description | |---|---| | Generic typing | Preserves the wrapped function's argument & return types exactly | | Lifecycle tracking | idle → pending → success \| error with timestamps | | Performance | Sub-millisecond duration via performance.now() | | Retries | Configurable count, exponential back-off with jitter, retryWhen predicate | | Timeout | Rejects with TimeoutError after the configured threshold | | Abort | Cancel via .abort() or an external AbortSignal | | Concurrency guard | Prevents overlapping .execute() calls | | Execution history | Optional ring-buffer of past runs | | Lifecycle callbacks | onStateChange, onSuccess, onError, onSettled | | Custom errors | TimeoutError, AbortError, ConcurrencyError — all instanceof-safe |


Installation

npm install async-tracer-ts

Or copy src/ into your project — there are zero runtime dependencies.


Quick Start

import { AsyncTracer } from 'async-tracer-ts';

const tracer = new AsyncTracer(fetchUser, {
  retries: 3,
  timeoutMs: 5000,
  onSuccess: (user) => console.log('Got user:', user),
});

const user = await tracer.execute(42);
console.log(tracer.state);
// {
//   status: 'success',
//   result: { id: 42, … },
//   error: null,
//   duration: 123.45,
//   retryCount: 0,
//   startedAt: '2026-02-10T…',
//   finishedAt: '2026-02-10T…'
// }

API Reference

new AsyncTracer(fn, options?)

| Param | Type | Description | |---|---|---| | fn | (...args: TArgs) => Promise<TReturn> | The async function to wrap | | options | AsyncTracerOptions<TReturn> | Optional configuration (see below) |

Options

| Option | Type | Default | Description | |---|---|---|---| | retries | number | 0 | Max retry attempts (original call doesn't count) | | retryBackoff | RetryBackoffConfig | { baseMs: 200, maxMs: 5000, factor: 2, jitter: true } | Back-off delays between retries | | retryWhen | (err: Error) => boolean | () => true | Predicate — return false to fail immediately | | timeoutMs | number | undefined | Per-execution timeout in ms | | signal | AbortSignal | undefined | External abort signal | | historyLimit | number | 0 | Ring-buffer size for execution history | | onStateChange | (state) => void | — | Called on every state transition | | onSuccess | (result, state) => void | — | Called after success | | onError | (error, state) => void | — | Called after failure | | onSettled | (state) => void | — | Called after success or failure |

Instance Properties

| Property | Type | Description | |---|---|---| | .state | Readonly<TracerState<T>> | Frozen snapshot of the current state | | .status | AsyncStatus | 'idle' \| 'pending' \| 'success' \| 'error' | | .result | T \| null | Last successful value | | .error | Error \| null | Last error | | .duration | number \| null | Last execution time (ms) | | .isPending | boolean | Convenience flag | | .isIdle | boolean | Convenience flag | | .history | readonly ExecutionRecord<T>[] | Past execution records |

Instance Methods

| Method | Description | |---|---| | .execute(...args) | Run the wrapped function — returns the resolved value or throws | | .abort(reason?) | Cancel an in-flight execution | | .reset() | Return to idle and clear history (throws if pending) |

Error Classes

| Error | When | |---|---| | TimeoutError | Execution exceeded timeoutMs | | AbortError | Execution was cancelled via signal or .abort() | | ConcurrencyError | .execute() called while already pending | | AsyncTracerError | Base class for all the above |


Development

# Install dependencies
npm install

# Type-check
npm run lint

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run the example
npm run example

# Build ESM + CJS
npm run build

Project Structure

async-tracer/
├── src/
│   ├── index.ts          # Barrel export
│   ├── async-tracer.ts   # Core class
│   ├── types.ts          # Type definitions
│   └── errors.ts         # Custom error classes
├── tests/
│   └── async-tracer.test.ts
├── example.ts            # Runnable demo
├── package.json
├── tsconfig.json         # Dev config (strict)
├── tsconfig.build.json   # ESM build
├── tsconfig.cjs.json     # CJS build
└── README.md

License

MIT