-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusage3.ts
58 lines (50 loc) · 1.48 KB
/
usage3.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
import { engine, EngineTask, run } from '../src';
import { writeTrace } from './common/writeTrace';
@engine({ id: 'complexEngineId' })
class MyDeepEngineTask extends EngineTask {
private depth: number;
private sequence: number;
private currDepth: number;
private currSequence: number;
constructor(depth: number = 10, sequence: number = 5) {
super();
this.depth = depth;
this.sequence = sequence;
this.currDepth = depth;
this.currSequence = sequence;
}
@run()
runInDepth(param: Array<string>): string {
const res = this.runSequence(this.currDepth);
if (this.currDepth > 0) {
this.currDepth = this.currDepth - 1;
return this.runInDepth(res);
}
this.currDepth = this.depth;
return `result1 for ${param} at level ${this.currDepth}`;
}
@run()
runSequence(depth: number) {
const res = [];
while (this.currSequence > 0) {
res.push(this.task(this.sequence));
this.currSequence = this.currSequence - 1;
}
this.currSequence = this.sequence;
res.push(`finished runSequenceInDepth for depth : ${depth}`);
return res;
}
@run()
task(param: string | number) {
return `run for sequence: ${param}`;
}
}
export async function generate() {
const myInstance = new MyDeepEngineTask(10, 5);
await myInstance.runInDepth(['starting']);
// Retrieve the trace
const trace = myInstance.engine.getTrace();
const jsonString = JSON.stringify(trace, null, 2);
writeTrace(jsonString);
}
generate().then();