Documentation
    Preparing search index...

    @abortor/core

    Hierarchical cancellation scopes for modern JavaScript runtimes.

    Built on top of the platform's native AbortController / AbortSignal, @abortor/core makes cancellation composable, structured, and developer‑friendly.


    • Hierarchical cancellation: disposing a parent scope cancels all of its descendants.
    • Scoped async: run work inside a scope.run(fn) and it automatically tracks lifetime.
    • Fetch integration: scope.fetch() threads the scope's signal into fetch calls.
    • Timeouts & composition: use scope.timeout(ms) or combine signals with composeAny().
    • Diagnostics: dev‑mode warnings, strict mode checks, and perf marks for profiling.
    • Fallbacks: uses AbortSignal.any() and AbortSignal.timeout() if available; provides shims otherwise.

    npm install @abortor/core
    # or
    pnpm add @abortor/core
    yarn add @abortor/core

    Requires Node.js 18+ or modern browsers with Abort APIs.


    import { scope } from "@abortor/core";

    // Create a new scope (optionally label it)
    const s = scope({ label: "SearchBox" });

    // Run async work inside the scope
    const result = await s.run(async (sc) => {
    const res = await sc.fetch("https://jsonplaceholder.typicode.com/users");
    return res.json();
    });

    // Later, cancel everything under this scope
    s.dispose("navigated away");

    Creates a new cancellation scope.

    const s = scope({ label: string, parent: Scope });
    

    A Scope exposes:

    • signal: AbortSignal — propagate into APIs like fetch
    • run(fn) — run async work bound to the scope
    • child(opts?) — create a nested scope
    • dispose(reason?) — cancel this scope and all children
    • fetch(input, init?) — like fetch, but auto‑uses the scope’s signal
    • timeout(ms, reason?) — create a timeout signal combined with this scope
    • race(promises) / all(promises) — helpers that cancel correctly

    Utility to create a scope, run work, and auto‑dispose.

    import { withScope } from "@abortor/core";

    await withScope(async (sc) => {
    await sc.fetch("/api/data");
    }); // auto‑disposed here
    import { configureDiagnostics } from "@abortor/core";

    configureDiagnostics({
    warnings: true,
    strict: false,
    perf: false,
    });
    • warnings: console.warn on leaks
    • strict: throw if missing signal usage
    • perf: mark/measure scopes in PerformanceTimeline

    Combine multiple signals; aborts when any does.

    Create a timeout signal, optionally combined with a parent.



    Also see:

    @abortor/angular – Angular-specific integration with component lifecycle-aware cancellation.

    @abortor/react — React hooks and utilities for cancellation-aware components (requires React 18+).

    View the Reference Docs