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

@xndrjs/tasks

v0.2.0

Published

Lazy async tasks utilities.

Readme

@xndrjs/tasks

Lazy asynchronous tasks: effects run only when awaited or chained like a Promise, with optional retry and predictable composability, mostly for infrastructure code.

Installation

npm install @xndrjs/tasks

Concepts

  • task(effect) — wraps effect: () => Promise<T>. Each await or .then/.catch/.finally invokes the effect again unless you memoize externally or use .inflightDedup.
  • .retry(shouldRetry, options?) — runs the underlying effect up to maxAttempts times (including the first try). shouldRetry(error, attempt) is async-friendly (e.g. backoff inside the predicate). Default maxAttempts is 3; maxAttempts must be an integer ≥ 1. At most one .retry() per chain.
  • .inflightDedup(key, registry?)key must be a symbol. Concurrent consumers using the same key in the same InflightRegistry share one in-flight run of the current effect (if you used .retry, the shared run is the whole retry sequence). At most one .inflightDedup() per chain. When that run settles, the slot is cleared. Omit registry to use the package default (process-wide); pass createInflightRegistry() to scope slots (tests, isolation).

Allowed shapes

  1. task(effect) only
  2. task(effect).retry(...) (no dedup)
  3. task(effect).inflightDedup(...) (no retry)
  4. task(effect).retry(...).inflightDedup(...) — retry before dedup

You cannot call .retry after .inflightDedup, chain two .retry, or chain two .inflightDedup (enforced by TypeScript).

Choosing a dedup key

  • Private logical operation (no accidental cross-package collisions): one module-level binding, e.g. const loadUsersOp = Symbol("loadUsers"). Each call to Symbol("loadUsers") without reusing the binding would create a different symbol; keep a single const and import it where needed.
  • Intentional global agreement (same slot for everyone using that name): Symbol.for("MY_APP:loadUsers") — the runtime registry is shared; only use when overlaps are desired.

Registry

  • createInflightRegistry() — returns a fresh Map-compatible store. Use when tests or subsystems must not share in-flight state with the rest of the process.

Example

import { sleep, task } from "@xndrjs/tasks";

const loadUsers = Symbol("loadUsers");

const usersTask = task(async () => fetch("/api/users"))
  .retry(
    async (error, attempt) => {
      if (!shouldRetry(error)) return false;

      // `attempt` starts at 0 after the first failure.
      // Wait: 200ms, 400ms, 800ms, 1600ms...
      const delayMs = 200 * 2 ** attempt;
      await sleep(delayMs);

      return true; // retry after sleep
    },
    {
      maxAttempts: 5,
    }
  )
  .inflightDedup(loadUsers)
  .then((response) => response.json());

const users = await usersTask;

API

Exported symbols: task, sleep, Task, TaskAfterRetry, TaskFinal, TaskPromise, InflightRegistry, createInflightRegistry, RetryPredicate, RetryOptions (maxAttempts?: number).

Caveats

  • Tasks are lazy and re-executed on each await/then; use .inflightDedup for in-flight coalescing, or memoize externally for other caching needs.
  • retry does not classify errors for you: domain-specific retry rules should live in shouldRetry.

License

MIT