feat: add CompositeAsyncHandler to support multiple handlers

This commit is contained in:
Joachim Van Herwegen
2020-05-28 10:55:29 +02:00
parent 57405f3e26
commit 4229932a3a
14 changed files with 275 additions and 23 deletions

View File

@@ -0,0 +1,24 @@
import { AsyncHandler } from '../../src/util/AsyncHandler';
export class StaticAsyncHandler<TOut> extends AsyncHandler<any, TOut> {
private readonly canHandleStatic: boolean;
private readonly handleStatic: TOut;
public constructor (canHandleStatic: boolean, handleStatic: TOut) {
super();
this.canHandleStatic = canHandleStatic;
this.handleStatic = handleStatic;
}
public async canHandle (): Promise<void> {
if (this.canHandleStatic) {
return;
}
throw new Error('Not supported.');
}
public async handle (): Promise<TOut> {
return this.handleStatic;
}
}