-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestAsyncComplex2.java
46 lines (34 loc) · 1.58 KB
/
TestAsyncComplex2.java
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
package generated;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import recaf.demo.cps.AsyncFull;
class MyPrinter{
public MyPrinter(){}
public Void print(String msg) {
System.out.println(msg);
return null;
}
}
public class TestAsyncComplex2 {
private static AsyncFull<Integer> alg = new AsyncFull<Integer>() {};
public Void pause(Integer sleeptime) {
try {
new Thread().sleep(sleeptime);
return null;
} catch (InterruptedException ex) {
return null;
}
}
CompletableFuture<Integer> op() {
return (CompletableFuture<Integer>)alg.Method(alg.Seq(alg.If(alg.Lt(alg.Lit(1), alg.Lit(2)), alg.Seq(alg.ExpStat(alg.Invoke(alg.This(this), "pause", alg.Lit(2500))), alg.Seq(alg.ExpStat(alg.Invoke(alg.New(MyPrinter.class), "print", alg.Lit("delayed op"))), alg.Return(alg.Lit(42))))), alg.Return(alg.Lit(41))));
}
CompletableFuture<Integer> op2() {
return (CompletableFuture<Integer>)alg.Method(alg.Seq(alg.If(alg.Lt(alg.Lit(1), alg.Lit(2)), alg.Await(alg.Invoke(alg.This(this), "op"), (x) -> { return alg.Await(alg.Invoke(alg.This(this), "op"), (y) -> { return alg.Return(alg.Plus(alg.Var("x", x), alg.Var("y", y))); }); })), alg.Seq(alg.ExpStat(alg.Invoke(alg.This(this), "pause", alg.Lit(5000))), alg.Return(alg.Lit(41)))));
}
public static void main(String[] args) throws InterruptedException, ExecutionException{
CompletableFuture<Integer> answer;
answer = new TestAsyncComplex2().op2();
new MyPrinter().print("main");
System.out.println(answer.get());
}
}