export type TaskStatus = 'not_found' | 'pending' | 'running' | 'completed' | 'failed'; interface Task { promise: Promise | null; startTime: number | null; parentTaskId: string | null; callback: (() => void) | null; status: TaskStatus; resolver?: ((promise: Promise) => void) | null; } /** * Task handler that manages dependencies and executes tasks asynchronously. * In Node.js, we don't need a thread pool since async operations run on the event loop. * This class provides dependency management and status tracking similar to Python's ThreadPoolTaskHandler. */ export declare class TaskHandler { private tasks; private retryCounts; private isTerminated; private terminationTime; /** * Handle the completion of a task, triggering any dependent child tasks. * @param taskId - The ID of the completed task. */ private handleTaskCompletion; /** * Handle parent task failure by rejecting dependent child tasks. * @param parentTaskId - The ID of the failed parent task. */ private handleTaskFailure; private failingTask; /** * Add or update a task in the tracking map. * @param taskId - The ID of the task. * @param promise - The promise representing the async task. * @param startTime - The start time of the task. * @param parentTaskId - The ID of the parent task (if dependent). * @param callback - The callback to run when the task is completed. * @param resolver - The resolver function for dependent tasks (to resolve the returned Promise). */ private addOrUpdateTask; /** * Submits a task for execution with optional parent dependency tracking. * @param taskId - The unique identifier for the task. * @param asyncFn - The async function to execute. Use async/await syntax to ensure synchronous errors are converted to rejected promises. * @param parentTaskId - (Optional) The ID of a parent task this task depends on. If provided, this task waits for parent completion. * @returns A promise that resolves to the task result or rejects if the task or its parent fails. */ submitTask(taskId: string, asyncFn: () => Promise, parentTaskId?: string): Promise; /** * Get the children of a parent task. * @param parentTaskId - The ID of the parent task. * @returns Array of child task information. */ getChildren(parentTaskId: string): Array<{ taskId: string; task: Task; }>; /** * Increment the retry count for a task. * @param taskId - The ID of the task. */ incrementRetry(taskId: string): void; /** * Get the status of a task. * @param taskId - The ID of the task. * @returns The status of the task. */ getStatus(taskId: string): TaskStatus; /** * Get the result of a completed task. * @param taskId - The ID of the task. * @returns The result of the task. * @throws Error if task not found or not completed. */ getResult(taskId: string): Promise; /** * Get the retry count for a task. * @param taskId - The ID of the task. * @returns The retry count. */ getRetryCount(taskId: string): number; /** * Check if all tasks are completed. * @returns True if all tasks are completed or failed, False otherwise. */ allTasksCompleted(): boolean; /** * Clean up completed and failed tasks that are no longer needed. * Removes tasks that: * - Are completed or failed * - Have no dependent children */ private cleanupTaskRetryMaps; /** * Terminate the task handler and clean up resources. * In Node.js, this is mainly for cleanup and doesn't need to stop a thread pool. * After termination, new tasks can still be submitted, but old promise handlers won't execute. */ terminate(): void; } export {};