UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

59 lines • 2.65 kB
/** * Async utilities for common asynchronous patterns and error handling */ /** * Wrapper for async operations with automatic error handling * Returns null on error instead of throwing */ export declare function withErrorHandling<T>(operation: () => Promise<T>, errorHandler?: (error: any) => void, context?: string): Promise<T | null>; /** * Execute multiple async operations in parallel with error handling */ export declare function parallelWithErrorHandling<T>(operations: (() => Promise<T>)[], errorHandler?: (error: any, index: number) => void): Promise<(T | null)[]>; /** * Retry an async operation with exponential backoff * * By default, does not retry on 4xx errors (client errors). * Use shouldRetry callback to customize retry behavior. */ export declare function retryAsync<T>(operation: () => Promise<T>, maxRetries?: number, baseDelay?: number, shouldRetry?: (error: any) => boolean): Promise<T>; /** * Debounce async function calls */ export declare function debounceAsync<T extends (...args: any[]) => Promise<any>>(func: T, delay: number): (...args: Parameters<T>) => Promise<ReturnType<T>>; /** * Throttle async function calls */ export declare function throttleAsync<T extends (...args: any[]) => Promise<any>>(func: T, limit: number, interval: number): (...args: Parameters<T>) => Promise<ReturnType<T>>; /** * Execute async operations sequentially with progress tracking */ export declare function sequentialWithProgress<T>(operations: (() => Promise<T>)[], onProgress?: (completed: number, total: number) => void): Promise<T[]>; /** * Batch async operations */ export declare function batchAsync<T>(items: T[], batchSize: number, processor: (batch: T[]) => Promise<void>): Promise<void>; /** * Create a cancellable async operation */ export declare function createCancellableAsync<T>(operation: (signal: AbortSignal) => Promise<T>): { execute: () => Promise<T>; cancel: () => void; }; /** * Timeout wrapper for async operations */ export declare function withTimeout<T>(operation: Promise<T>, timeoutMs: number, timeoutMessage?: string): Promise<T>; /** * Execute async operation with loading state */ export declare function withLoadingState<T>(operation: () => Promise<T>, setLoading: (loading: boolean) => void): Promise<T>; /** * Create a promise that resolves after a delay */ export declare const delay: (ms: number) => Promise<void>; /** * Execute async operation with retry on specific errors */ export declare function retryOnError<T>(operation: () => Promise<T>, retryableErrors: (string | number)[], maxRetries?: number): Promise<T>; //# sourceMappingURL=asyncUtils.d.ts.map