@mlightcad/common
Version:
The common package provides shared utilities and base classes that are used across the RealDWG-Web ecosystem. This package contains fundamental components for color management, event handling, logging, performance monitoring, and file loading operations.
70 lines • 2.27 kB
TypeScript
/**
* Represents a named unit of work with an asynchronous or synchronous execution function.
* @template TIn Input type
* @template TOut Output type
*/
export declare class AcCmTask<TIn, TOut> {
/**
* Name of the task (for logging/debugging purposes)
*/
readonly name: string;
constructor(name: string);
/**
* Executes the task.
*/
run(_input: TIn): TOut | Promise<TOut>;
}
/**
* Reports progress after a task completes.
* @param progress A number between 0 and 1 indicating task completion
* @param task The task that was just completed
*/
type AcCmProgressCallback = (progress: number, task: AcCmTask<unknown, unknown>) => void;
/**
* Callback function to handle final output.
*/
export type AcCmCompleteCallback<T> = (finalResult: T) => void;
/**
* Handles errors during task execution.
* @param error The error thrown
* @param taskIndex Index of the failed task
* @param task The task that failed
*/
type AcCmErrorCallback = (error: unknown, taskIndex: number, task: AcCmTask<unknown, unknown>) => void;
/**
* Type-safe task scheduler that executes a chain of named tasks in order,
* passing results between them and stopping on the first failure.
*
* @template TInitial Initial input type
* @template TFinal Final output type
*/
export declare class AcCmTaskScheduler<TInitial, TFinal = TInitial> {
private tasks;
private onProgress;
private onComplete;
private onError;
/**
* Adds a task to the execution queue.
*
* @param task Task instance with name and run function
*/
addTask<TIn, TOut>(task: AcCmTask<TIn, TOut>): void;
/**
* Sets a callback to receive progress updates.
*/
setProgressCallback(callback: AcCmProgressCallback): void;
/**
* Sets a callback to be called after successful completion of all tasks.
*/
setCompleteCallback(callback: AcCmCompleteCallback<TFinal>): void;
/**
* Sets a callback to be called if any task throws an error.
*/
setErrorCallback(callback: AcCmErrorCallback): void;
/**
* Starts execution of the task queue with the given initial input.
*/
run(initialData: TInitial): Promise<void>;
}
export {};
//# sourceMappingURL=AcCmTaskScheduler.d.ts.map