corda/sgx-jvm/avian/test/extra/Continuations.java

59 lines
1.5 KiB
Java
Raw Normal View History

package extra;
2009-05-16 08:01:07 +00:00
import static avian.Continuations.callWithCurrentContinuation;
import avian.Function;
2009-05-16 08:01:07 +00:00
import avian.Callback;
public class Continuations {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
2009-05-16 08:01:07 +00:00
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);
2009-05-17 00:39:08 +00:00
try {
callWithCurrentContinuation(new Function<Callback<Integer>,Integer>() {
public Integer call(Callback<Integer> continuation) {
2009-05-17 00:39:08 +00:00
continuation.handleException(new MyException());
2009-05-17 03:41:27 +00:00
throw new AssertionError();
2009-05-17 00:39:08 +00:00
}
});
2009-05-17 03:41:27 +00:00
throw new AssertionError();
2009-05-17 00:39:08 +00:00
} catch (MyException e) {
e.printStackTrace();
}
try {
callWithCurrentContinuation(new Function<Callback<Integer>,Integer>() {
public Integer call(Callback<Integer> continuation)
2009-05-17 00:39:08 +00:00
throws MyException
{
throw new MyException();
}
});
2009-05-17 03:41:27 +00:00
throw new AssertionError();
2009-05-17 00:39:08 +00:00
} catch (MyException e) {
e.printStackTrace();
}
2009-05-16 08:01:07 +00:00
}
2009-05-17 00:39:08 +00:00
private static class MyException extends Exception { }
2009-05-16 08:01:07 +00:00
}