Skip to content

Feature request: AbortController support #169

Description

@pveierland

Is your feature request related to a problem?

In the current data loader interface, there is no support for an abort signal during loading. This means that loading operations that require cleanup have to implement workarounds to ensure cleanup if loading is cancelled.

Describe the solution you'd like

Libraries such as React Query provides a parameter signal?: AbortSignal to support aborting ongoing queries:

https://tanstack.com/query/latest/docs/framework/react/guides/query-functions#queryfunctioncontext

https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation

A possible solution could be to add a second object parameter to each loader function, e.g.:

type TreeDataLoader<T> = {
    getItem: (itemId: string, options: TreeDataLoaderOptions) => T | Promise<T>;
    getChildren: (itemId: string, options: TreeDataLoaderOptions) => string[] | Promise<string[]>;
} | {
    getItem: (itemId: string, options: TreeDataLoaderOptions) => T | Promise<T>;
    getChildrenWithData: (itemId: string), options: TreeDataLoaderOptions => {
        id: string;
        data: T;
    }[] | Promise<{
        id: string;
        data: T;
    }[]>;
};

interface TreeDataLoaderOptions {
    abortSignal?: AbortSignal;
}

Having an options object should allow further flexibility for the API.

Describe alternatives you've considered

A workaround may be to implement a timeout system to handle cleanup without a provided AbortSignal.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions