Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

promistop

ashishcumar692MIT1.0.15TypeScript support: included

Promistop is a lightweight utility that adds cancellation support to any async function. It extends promises with .cancel() and .isCancelled() methods, optionally using AbortController. Ideal for JavaScript apps using async operations like fetch, time

JavaScript, Promises, Cancelable Promise, AbortController, Async utilities, React, Fetch cancel, Promise cancellation, Abortable tasks, Cancellable tasks

readme

Promistop

A lightweight utility to create cancellable promises in JavaScript

Promistop adds .cancel() and .isCancelled() methods to any async task, with optional AbortController support.

Build Fast Lightweight Npm-Version Trusted No Dependency

🔧 Features

  • Cancel any async function using .cancel(reason?)
  • Check if a promise was cancelled using .isCancelled()
  • Optional support for AbortSignal (e.g., for fetch)
  • Tiny and framework-agnostic

📦 Installation

npm install promistop

🚀 Usage

- API Call with fetch and AbortSignal

import { makeCancellable } from "promistop";

const cancellable = makeCancellable(
  async ({ signal }) => {
    const res = await fetch("/api/data", { signal });
    return res.json();
  },
  { abortable: true }
);

cancellable
  .then((data) => console.log(data))
  .catch((err) => console.error(err));

// Cancel the request if needed
cancellable.cancel("User navigated away");

- Wrapping a setTimeout

import { makeCancellable } from "promistop";

const delay = (ms: number) =>
  makeCancellable(
    () =>
      new Promise((resolve) => {
        const id = setTimeout(() => resolve("Done waiting"), ms);
        // Optional cleanup if extending
        return () => clearTimeout(id);
      }),
    { cancelReason: "Timeout manually cancelled" }
  );

const timeoutPromise = delay(3000);

timeoutPromise.then(console.log).catch(console.error);

// Cancel before it completes
setTimeout(() => {
  timeoutPromise.cancel("Cancelled early");
}, 1000);

🧩 API

makeCancellable(asyncFn, options?)

Creates a cancellable promise from any async function.

Parameters:

  • asyncFn: (params?: { signal?: AbortSignal }) => Promise<T> | T – your async task
  • options:
    • abortable?: boolean – enable AbortController support
    • cancelReason?: string – default cancel message

Returns:

A CancellablePromise<T> with:

  • .cancel(reason?) - Cancels the promise with an optional reason
  • .isCancelled() - Returns whether the promise has been cancelled

⚠️ Issues/Errors

For any hiccups with the package, drop an email to Kumarashish87998@gmail.com with "Error || Promistop" as the subject. 📧