corda/sgx-jvm/avian/test/extra/Continuations.java
Andras Slemmer 9bb3d6b972 Add 'sgx-jvm/avian/' from commit '09e4fe60d01f4f4bfb6b2976973bb4913ef61edc'
git-subtree-dir: sgx-jvm/avian
git-subtree-mainline: f978eab8d1
git-subtree-split: 09e4fe60d0
2017-03-13 12:18:24 +00:00

59 lines
1.5 KiB
Java

package extra;
import static avian.Continuations.callWithCurrentContinuation;
import avian.Function;
import avian.Callback;
public class Continuations {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
public static void main(String[] args) throws Exception {
expect
(callWithCurrentContinuation
(new Function<Callback<Integer>,Integer>() {
public Integer call(Callback<Integer> continuation) {
continuation.handleResult(42);
throw new AssertionError();
}
}) == 42);
expect
(callWithCurrentContinuation
(new Function<Callback<Integer>,Integer>() {
public Integer call(Callback<Integer> continuation) {
return 43;
}
}) == 43);
try {
callWithCurrentContinuation(new Function<Callback<Integer>,Integer>() {
public Integer call(Callback<Integer> continuation) {
continuation.handleException(new MyException());
throw new AssertionError();
}
});
throw new AssertionError();
} catch (MyException e) {
e.printStackTrace();
}
try {
callWithCurrentContinuation(new Function<Callback<Integer>,Integer>() {
public Integer call(Callback<Integer> continuation)
throws MyException
{
throw new MyException();
}
});
throw new AssertionError();
} catch (MyException e) {
e.printStackTrace();
}
}
private static class MyException extends Exception { }
}