feat:处理器初步实现---有接上了新优化,回显需要再看下
This commit is contained in:
33
samples/demoDataHandleServer.ts
Normal file
33
samples/demoDataHandleServer.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user