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 🙏

© 2025 – Pkg Stats / Ryan Hefner

abortium

v0.1.0

Published

Halt a process of asynchronous steps using an AbortSignal

Downloads

3

Readme

Abortium

Halt a process of asynchronous steps using an AbortSignal.

Why

JavaScript is single-threaded, which means you can't really halt a running process. However, it provides us an API called AbortController that is basically usable only in specific scenarios and APIs, such as fetch and addEventListener.

If you want to use the AbortController API in your code, you need to wait for each function to finish, and check between the function runs whether the AbortSignal has been aborted. This is a tedious task, and it can be easily forgotten:

const controller = new AbortController();

async function processData() {
  const result1 = await heavyDataProcessing(data, controller.signal);

  if (controller.signal.aborted) {
    return;
  }

  const result2 = await heavyDataProcessing(result1, controller.signal);

  if (controller.signal.aborted) {
    return;
  }

  const result3 = await heavyDataProcessing(result2, controller.signal);

  if (controller.signal.aborted) {
    return;
  }

  const result4 = await heavyDataProcessing(result3, controller.signal);

  if (controller.signal.aborted) {
    return;
  }

  return result4;
}

button.addEventListener('click', () => {
  controller.abort();
});

What

Abortium solves this problem by letting you create a process of asynchronous steps that will be halted when the AbortSignal is aborted. It uses the AbortController API under the hood, and provides a more convenient API to use:

import { abortableProcess } from 'abortium';

const controller = new AbortController();

async function processData() {
  const process = abortableProcess(controller.signal)
    .then((_, signal) => heavyDataProcessing(data, signal))
    .then((result1, signal) => heavyDataProcessing(result1, signal))
    .then((result2, signal) => heavyDataProcessing(result2, signal))
    .then((result3, signal) => heavyDataProcessing(result3, signal));

  const finalResult = await process.execute();

  return finalResult;
}

It's somewhat similar to the Promise API. You chain the steps using .then(), and the library gives you the previous step's result and the AbortSignal as arguments.

Each step in the chain is typed, so the next step will have the correct type for the previous step's result.

When the AbortSignal is aborted, the process will be halted, and all queued steps will be skipped.