33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { Processor, ProcessorCollection, ProcessorModule } from "../src/device";
|
|
|
|
|
|
export class ProcessorManager<T, R> implements ProcessorCollection<T, R> {
|
|
private processors = new Map<string, Processor<T, R>>();
|
|
private currentProcessor?: Processor<T, R>;
|
|
|
|
constructor(){
|
|
|
|
}
|
|
/** 注册模块流程 */
|
|
registerProcessor(name: string, processor: Processor<T, R>): this {
|
|
this.processors.set(name, processor);
|
|
return this;
|
|
}
|
|
/** 使用处理器 */
|
|
useProcessor(name: string): Processor<T, R> {
|
|
const processor = this.processors.get(name);
|
|
if (!processor) {
|
|
throw new Error(`Processor ${name} not found`);
|
|
}
|
|
this.currentProcessor = processor;
|
|
return processor;
|
|
}
|
|
/** 获取处理器 */
|
|
getProcessor(name: string): Processor<T, R> | undefined {
|
|
return this.processors.get(name);
|
|
}
|
|
/** 获取正在使用的处理器 */
|
|
getCurrentProcessor(): Processor<T, R> | undefined {
|
|
return this.currentProcessor;
|
|
}
|
|
} |