corda/test/extra/Continuations.java

55 lines
1.6 KiB
Java
Raw Normal View History

2009-05-16 08:01:07 +00:00
package extra;
import static avian.Continuations.callWithCurrentContinuation;
import avian.CallbackReceiver;
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 CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation) {
continuation.handleResult(42);
throw new RuntimeException("unreachable");
}
}) == 42);
expect(callWithCurrentContinuation(new CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation) {
return 43;
}
}) == 43);
2009-05-17 00:39:08 +00:00
try {
callWithCurrentContinuation(new CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation) {
continuation.handleException(new MyException());
throw new RuntimeException("unreachable");
}
});
throw new RuntimeException("unreachable");
2009-05-17 00:39:08 +00:00
} catch (MyException e) {
e.printStackTrace();
}
try {
callWithCurrentContinuation(new CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation)
throws MyException
{
throw new MyException();
}
});
throw new RuntimeException("unreachable");
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
}