UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio

74 lines (73 loc) 2.2 kB
/** * Timeout Utilities * * Wrapper functions for adding timeout protection to async operations. */ /** * Error thrown when an operation times out. */ export declare class TimeoutError extends Error { readonly timeoutMs: number; /** * Creates a new TimeoutError. * * @param message - Error message describing the timeout * @param timeoutMs - The timeout duration that was exceeded */ constructor(message: string, timeoutMs: number); } /** * Execute a promise with timeout protection. * * Wraps a promise and rejects with a TimeoutError if the operation * takes longer than the specified duration. * * @param promise - The promise to wrap with timeout * @param ms - Maximum time to wait in milliseconds * @param message - Optional custom error message for timeout * @returns Promise that resolves with the result or rejects on timeout * @throws {TimeoutError} If the operation exceeds the timeout duration * * @example * ```typescript * const result = await withTimeout( * fetchData(), * 5000, * 'Data fetch timed out' * ); * ``` * * @example * ```typescript * try { * const data = await withTimeout(slowOperation(), 3000); * } catch (error) { * if (error instanceof TimeoutError) { * console.log(`Timed out after ${error.timeoutMs}ms`); * } * } * ``` */ export declare function withTimeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>; /** * Execute a function with timeout protection. * * Alternative signature that accepts a function instead of a promise, * useful when you want to delay starting the operation. * * @param fn - Async function to execute * @param ms - Maximum time to wait in milliseconds * @param message - Optional custom error message for timeout * @returns Promise that resolves with the function result or rejects on timeout * @throws {TimeoutError} If the operation exceeds the timeout duration * * @example * ```typescript * const result = await withTimeoutFn( * () => fetchData(), * 5000, * 'Data fetch timed out' * ); * ``` */ export declare function withTimeoutFn<T>(fn: () => Promise<T>, ms: number, message?: string): Promise<T>;