-
Notifications
You must be signed in to change notification settings - Fork 0
/
executor.ts
63 lines (51 loc) · 1.5 KB
/
executor.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { ExecResult } from "./exec_result";
import { ExecFailureError } from "./exec_failure_error";
import { ExecParam } from "./exec_param";
import DaiTol from ".";
export class Executor {
public execResult: ExecResult
public execParam: ExecParam
constructor(options?: Map<string, any>) {
this.execParam = options ? ExecParam.from(options) : new ExecParam()
this.execResult = new ExecResult()
}
public getResult(name: string): any {
return this.execResult.get(name)
}
public getParam(name: string): any {
return this.execParam.get(name)
}
public static async callAsync(options?: Map<string, any>): Promise<ExecResult> {
let object = options ? new this(options) : new this()
try {
await object.callAsync()
return object.execResult
}
catch (ex) {
return object.handleError(ex);
}
}
public static call(options?: Map<string, any>): ExecResult {
let object = options ? new this(options) : new this()
try {
object.call()
return object.execResult
}
catch (ex) {
return object.handleError(ex);
}
}
public handleError(ex: any): ExecResult {
let error = ex as Error;
this.execResult.failByMessage(error.message)
return this.execResult
}
// override and set execResult
public async callAsync() {
throw new DaiTol.ExecFailureError('callAsync need to be implemented')
}
// override and set execResult
public call() {
throw new DaiTol.ExecFailureError('call need to be implemented')
}
}