@happy-ts/fetch-t
    Preparing search index...

    Interface FetchTask<T>

    Represents an abortable fetch operation with control methods.

    Returned when abortable: true is set in the fetch options. Provides the ability to cancel the request and check its abort status.

    import { fetchT, type FetchTask } from '@happy-ts/fetch-t';

    interface User {
    id: number;
    name: string;
    }

    const task: FetchTask<User> = fetchT<User>('https://api.example.com/user/1', {
    abortable: true,
    responseType: 'json',
    });

    // Check if aborted
    console.log('Is aborted:', task.aborted); // false

    // Abort with optional reason
    task.abort('User navigated away');

    // Access the result (will be an error after abort)
    const result = await task.result;
    result.inspectErr((err) => console.log('Aborted:', err.message));
    interface FetchTask<T> {
        aborted: boolean;
        result: FetchResult<T>;
        abort(reason?: any): void;
    }

    Type Parameters

    • T

      The type of the data expected in the response.

    Index

    Properties

    Methods

    Properties

    aborted: boolean

    Indicates whether the fetch task has been aborted.

    Returns true if abort() was called or if the request timed out.

    result: FetchResult<T>

    The result promise of the fetch task.

    Resolves to Ok<T> on success, or Err<Error> on failure (including abort).

    Methods

    • Aborts the fetch task, optionally with a reason.

      Once aborted, the result promise will resolve to an Err containing an AbortError. The abort reason can be any value and will be passed to the underlying AbortController.abort().

      Parameters

      • Optionalreason: any

        An optional value indicating why the task was aborted. This can be an Error, string, or any other value.

      Returns void