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