Repository navigation
Expand file tree
/
Copy pathIndex.ets
More file actions
121 lines (103 loc) · 2.77 KB
/
Copy pathIndex.ets
File metadata and controls
121 lines (103 loc) · 2.77 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class CompletableFutureExample {
private task1(): string | null {
console.log("T1: 1");
for (let i = 0; i < 1000; i++);
console.log("T1: 2");
for (let i = 0; i < 1000; i++);
return null;
}
private task2(): string {
console.log("T2: 1");
for (let i = 0; i < 1000; i++);
console.log("T2: 2");
for (let i = 0; i < 1000; i++);
console.log("T2: 3");
for (let i = 0; i < 1000; i++);
return " 锟斤拷锟斤拷 ";
}
private task3(tea: string | undefined): string {
console.log("T1: 1" + tea);
console.log("T1: 2");
return " 锟较诧拷:" + tea;
}
public static main(): void {
const example = new CompletableFutureExample();
const tea: string[] = [""];
const t1 = new Thread(() => {
example.task1();
});
const t2 = new Thread(() => {
tea[0] = example.task2();
});
t1.start();
t2.start();
const result = example.task3(tea[0]);
}
}
class SerialRelation {
private static task1(): string {
return "Hello World";
}
private static task2(s: string): string {
return s + " QQ";
}
private static task3(s: string): string {
return s.toUpperCase();
}
public static main(): void {
let result = this.task1();
result = this.task2(result);
result = this.task3(result);
}
}
class ConvergeRelation {
private static task1(): string {
const t = this.getRandom(5, 10);
for (let i = 0; i < 1000; i++);
return t.toString();
}
private static task2(): string {
const t = this.getRandom(5, 10);
for (let i = 0; i < 1000; i++);
return t.toString();
}
private static getRandom(i: number, j: number): number {
return Math.floor(Math.random() * (j - i)) + i;
}
public static main(): void {
const result1 = this.task1();
const result2 = this.task2();
const result = result1 !== null ? result1 : result2;
}
}
class ExceptionHandler {
private static task(): number {
try {
return 7 / 0;
} catch (e) {
if (e instanceof Error) {
return 0;
}
throw e;
}
}
private static task2(r: number): number {
return r * 10;
}
public static main(): void {
let result = this.task();
result = this.task2(result);
}
}
class Thread {
private runnable: () => void;
constructor(runnable: () => void) {
this.runnable = runnable;
}
public start(): void {
setTimeout(this.runnable, 0);
}
}
if (isMainThread()) {
// You can put the entry of your code here to test.
}