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

@gantryland/task

v0.5.0

Published

Minimal async task with reactive state

Readme

@gantryland/task

Minimal async task primitive with reactive state and latest-run-wins behavior.

Installation

npm install @gantryland/task

Quick Start

import { Task } from "@gantryland/task";

type User = { id: string; name: string };

const userTask = new Task<User, [string]>((id) =>
  fetch(`/api/users/${id}`).then((r) => r.json()),
);

await userTask.run("42");

Exports

| Export | Kind | What it does | | --- | --- | --- | | Task | Class | Provides reactive async state with latest-run-wins behavior. | | TaskFn | Type | Represents the async function signature used by Task.run. | | TaskState | Type | Represents the task state snapshot shape. | | TaskOperator | Type | Represents a function wrapper used by task.pipe(...). |

API Reference

Task

new Task<T, Args extends unknown[] = []>(fn: TaskFn<T, Args>)

| Member | Signature | Description | | --- | --- | --- | | getState | () => TaskState<T> | Returns the current state snapshot. | | subscribe | (listener: (state: TaskState<T>) => void) => () => void | Subscribes to state updates and emits the current state immediately. | | run | (...args: Args) => Promise<T> | Runs the task function and updates state. Rejects on failure or cancellation. | | fulfill | (data: T) => T | Sets success state immediately and returns data. | | cancel | () => void | Cancels the in-flight run, if any. | | reset | () => void | Resets to the initial stale idle state. | | pipe | Overloaded pipe(...operators) returning a typed Task chain | Returns a new task composed from this task function. |

TaskFn

type TaskFn<T, Args extends unknown[] = []> = (...args: Args) => Promise<T>;

TaskOperator

type TaskOperator<In, Out, Args extends unknown[] = []> = (
  taskFn: TaskFn<In, Args>,
) => TaskFn<Out, Args>;

TaskState

type TaskState<T> = {
  data: T | undefined;
  error: Error | undefined;
  isLoading: boolean;
  isStale: boolean;
};

Practical Use Cases

Example: Load on Demand

const searchTask = new Task<string[], [string]>((query) =>
  fetch(`/api/search?q=${encodeURIComponent(query)}`).then((r) => r.json()),
);

await searchTask.run("term");

Example: Optimistic Local Fulfill

const profileTask = new Task(async () => fetch("/api/profile").then((r) => r.json()));

profileTask.fulfill({ id: "42", name: "Local Name" });

Example: Cancel Superseded Work

const reportTask = new Task(async (id: string) =>
  fetch(`/api/reports/${id}`).then((r) => r.json()),
);

void reportTask.run("a");
void reportTask.run("b");

Example: Derive a Piped Task

const baseTask = new Task(async (id: string) =>
  fetch(`/api/users/${id}`).then((r) => r.json()),
);

const hardenedTask = baseTask.pipe(
  (taskFn) => async (...args: [string]) => {
    const value = await taskFn(...args);
    return value;
  },
);

Runtime Semantics

  • Starting run(...args) clears error, sets isLoading: true, and sets isStale: false.
  • If a later run starts before an earlier one settles, the earlier run is canceled.
  • Canceled runs reject with AbortError and do not write error to state.
  • Failed runs keep previous data, normalize non-Error throws, and write error.
  • fulfill, cancel, and reset cancel any in-flight run.
  • getState and subscribe expose immutable snapshots, not mutable internal state references.
  • pipe never mutates the source task; it always returns a new Task instance.