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

isotropic-cancel

v0.1.0

Published

Manage the cancellation of an asynchronous task with reasons, abort signals, and standardized errors

Readme

isotropic-cancel

npm version License

A utility that manages the cancellation of an asynchronous task with reasons, abort signals, and standardized errors.

Why Use This?

  • One Cancellation Contract: The same reusable cancel({ reason, signal, silent }) semantics implemented in one place
  • AbortSignal Integration: Bind any number of AbortSignal instances before or after creation, with automatic listener cleanup
  • Standardized Errors: Generates consistent AbortError and CanceledError objects with configurable subjects and details
  • Silent Cancellation: Cancel a task's side effects without delivering an error
  • Resource Management: Supports using declarations via Symbol.dispose

Installation

npm install isotropic-cancel

Overview

A Cancel instance represents the cancelable phase of a pending task. It begins pending. It ends in exactly one of two ways:

  • cancel() - the task should stop. Signal listeners are removed and the onCancel function is executed with a standardized error describing why.
  • complete() - the task completed on its own. Signal listeners are removed and nothing else happens.

Once canceled or completed, all further cancel and complete calls are ignored. The onCancel function defines what cancellation means for the specific task: reject a promise, remove a queued callback, abort a controller, clear a timer, or anything else.

Usage

import _Cancel from 'isotropic-cancel';

const _somethingAsync = ({
    signal
} = {}) => {
    const {
            promise,
            reject,
            resolve
        } = Promise.withResolvers(),

        cancel = _Cancel({
            onCancel: ({
                error
            }) => {
                // Stop the task however is appropriate, then deliver the error.
                if (error) {
                    reject(error);
                }
            },
            signal,
            subject: 'Something async'
        });

    beginTheTask(result => {
        if (!cancel.completed) {
            cancel.complete();
            resolve(result);
        }
    });

    promise.cancel = config => {
        cancel.cancel(config);

        return promise;
    };

    return promise;
};

API

Constructor

_Cancel(config)

Creates a new cancel instance. Cancel is created with isotropic-make, so it can be called with or without new.

Parameters

  • config (Object, optional):
    • details (Object, optional): Included as the details of generated errors
    • onCancel (Function, optional): Executed exactly once when the instance is canceled, with a config object:
      • error (Error): The cancellation error, or undefined when canceled silently
      • silent (Boolean): Whether the cancellation was silent
    • signal (AbortSignal, optional): A signal to bind immediately. If it is already aborted, the instance cancels synchronously during construction.
    • subject (String, optional): The subject of generated error messages, as in ${subject} aborted and ${subject} canceled. Default: 'Task'

cancel(config)

Requests cancellation.

Parameters

  • config (Object, optional):
    • reason (Error, optional): A custom error to deliver instead of the generated CanceledError
    • signal (AbortSignal, optional): When given a signal that has not yet aborted, the instance is not canceled; instead the signal is bound so that its abort cancels the instance later. When given a signal that has already aborted, the instance cancels immediately with an AbortError wrapping signal.reason.
    • silent (Boolean, optional): Cancel without delivering an error. onCancel is still executed so the task can stop, but its error is undefined. When registering a signal, the silent value is remembered and applied when the signal aborts. Default: false

Returns

  • (Cancel): The instance, for chaining

The same signal can be bound multiple times without duplicate listeners, and multiple different signals can each be bound. When the instance settles or cancels, all listeners are removed.

complete()

Marks the task as complete. Signal listeners are removed and any pending cancellation sources are ignored from this point on. Returns the instance.

canceled

A read-only Boolean property indicating whether the instance was canceled.

completed

A read-only Boolean property indicating whether the instance has ended, either by cancel() or by complete().

Symbol.dispose()

Completes the instance, enabling using declarations.

Cancel.abortError(config)

A static factory for the standardized AbortError.

Parameters

  • config (Object, optional):
    • details (Object, optional): Error details
    • signal (AbortSignal, optional): The aborted signal; its reason becomes the error's error property
    • subject (String, optional): Default: 'Task'

Returns

  • (Error): An isotropic-error with name 'AbortError' and message ${subject} aborted

Cancel.canceledError(config)

A static factory for the standardized CanceledError.

Parameters

  • config (Object, optional):
    • details (Object, optional): Error details
    • subject (String, optional): Default: 'Task'

Returns

  • (Error): An isotropic-error with name 'CanceledError' and message ${subject} canceled

Errors

| Name | Cause | error property | | --------------- | ----------------------------- | ---------------- | | AbortError | Canceled via an AbortSignal | signal.reason | | CanceledError | Canceled without a reason | - |

When cancel is called with a reason, that reason is delivered as-is instead of a generated error.

Related Packages

Contributing

Please refer to CONTRIBUTING.md for contribution guidelines.

Issues

If you encounter any issues, please file them at https://github.com/ibi-group/isotropic-cancel/issues