import { type HookErrorHandler } from '../utils/errors.js'; /** Status of the latest active or completed async run. @public */ export type AsyncStatus = 'idle' | 'pending' | 'success' | 'error'; /** State exposed by {@link useAsync}. @public */ export interface AsyncState { /** Lifecycle status of the latest run. */ readonly status: AsyncStatus; /** Most recently resolved data, retained while a later run is pending. */ readonly data: T | undefined; /** Most recent task error, cleared when a new run starts or reset is called. */ readonly error: unknown; } /** Options for {@link useAsync}. @public */ export interface UseAsyncOptions { /** Starts the task in an effect after commit when true. */ readonly immediate?: boolean; /** Observes the latest run's task error before the returned promise rejects. */ readonly onError?: HookErrorHandler; } /** State and stable actions returned by {@link useAsync}. @public */ export interface UseAsyncResult extends AsyncState { /** Aborts the prior run, if any, and starts the latest committed task. */ readonly run: () => Promise; /** Aborts the active run and returns the status to idle. */ readonly cancel: () => void; /** Aborts the active run and restores the complete initial state. */ readonly reset: () => void; } /** An abort-aware task accepted by {@link useAsync}. @public */ export type AsyncTask = (signal: AbortSignal) => Promise | T; /** * Runs an abortable task while ignoring stale state updates. * * @param task - The latest committed task invoked by run. * @param options - Controls whether a run starts automatically after commit. * @returns Async state plus stable run, cancel, and reset actions. * @public */ export declare function useAsync(task: AsyncTask, options?: UseAsyncOptions): UseAsyncResult;