blob: d606ac0b5bd3169e040aa35658b72698d7ef2a78 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { inject, injectable } from "tsyringe";
import * as operations from "../../shared/operations";
import OperatorFactory from "../operators/OperatorFactory";
import RepeatUseCase from "../usecases/RepeatUseCase";
@injectable()
export default class OperationController {
constructor(
private readonly repeatUseCase: RepeatUseCase,
@inject("OperatorFactory")
private readonly operatorFactory: OperatorFactory
) {}
async exec(repeat: number, op: operations.Operation): Promise<any> {
await this.doOperation(repeat, op);
if (this.repeatUseCase.isRepeatable(op)) {
this.repeatUseCase.storeLastOperation(op);
}
}
private async doOperation(
repeat: number,
operation: operations.Operation
): Promise<any> {
const operator = this.operatorFactory.create(operation);
for (let i = 0; i < repeat; ++i) {
// eslint-disable-next-line no-await-in-loop
await operator.run();
}
}
}
|