type PipeCallback
= (input: P, output: T) => T | Promise;
export class Pipeline {
private callbacks = [];
use(callbackFn: PipeCallback
) {
this.callbacks.push(callbackFn);
return this;
}
async exec(input?: P, output?: T): Promise {
let result: any = output;
for (const callback of this.callbacks) {
result = await callback(input, result);
}
return result as T;
}
execSync(input?: P, output?: T): T {
let result: any = output;
for (const callback of this.callbacks) {
result = callback(input, result);
}
return result as T;
}
}