/** * useAsyncProgress Hook * * Generic hook for async operations with progress tracking, cancellation, * and state machine management. Consolidates common patterns from * useUpdates, useSync, and other async hooks. * * @since v1.35.0 */ /** * Async operation status */ export type AsyncStatus = 'idle' | 'loading' | 'success' | 'error'; /** * State for async operations with progress */ export interface AsyncProgressState { /** Result data (null until success) */ data: T | null; /** Error if operation failed */ error: Error | null; /** Current status */ status: AsyncStatus; /** Progress percentage (0-100) */ progress: number; /** Whether operation is currently running */ isLoading: boolean; /** Whether operation completed successfully */ isSuccess: boolean; /** Whether operation failed */ isError: boolean; /** Whether operation is idle (not started or reset) */ isIdle: boolean; } /** * Options for useAsyncProgress */ export interface UseAsyncProgressOptions { /** Called when progress updates */ onProgress?: (progress: number) => void; /** Called when operation succeeds */ onSuccess?: (data: T) => void; /** Called when operation fails */ onError?: (error: Error) => void; /** Called when operation starts */ onStart?: () => void; /** Called when operation is cancelled */ onCancel?: () => void; /** Initial data value */ initialData?: T | null; } /** * Return type for useAsyncProgress */ export interface UseAsyncProgressReturn { /** Current state */ state: AsyncProgressState; /** Execute the async operation */ execute: () => Promise; /** Cancel the current operation */ cancel: () => void; /** Reset state to idle */ reset: () => void; /** Set progress manually (0-100) */ setProgress: (progress: number) => void; } /** * Async function signature with abort signal and progress callback */ export type AsyncProgressFn = (signal: AbortSignal, onProgress: (progress: number) => void) => Promise; /** * Hook for managing async operations with progress tracking * * @param asyncFn - Async function that receives abort signal and progress callback * @param options - Configuration options * @returns State and control methods * * @example * ```typescript * const { state, execute, cancel } = useAsyncProgress( * async (signal, onProgress) => { * const result = await fetchWithProgress(url, { signal, onProgress }); * return result; * }, * { * onSuccess: (data) => console.log('Done!', data), * onError: (error) => console.error('Failed:', error), * } * ); * * // Start operation * execute(); * * // Cancel if needed * cancel(); * * // Check state * if (state.isLoading) { * console.log(`Progress: ${state.progress}%`); * } * ``` */ export declare function useAsyncProgress(asyncFn: AsyncProgressFn, options?: UseAsyncProgressOptions): UseAsyncProgressReturn; //# sourceMappingURL=useAsyncProgress.d.ts.map