corda/test/extra/Continuations.java

53 lines
1.5 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 {
public static void main(String[] args) throws Exception {
System.out.println
("result: " +
callWithCurrentContinuation(new CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation) {
continuation.handleResult(42);
2009-05-17 00:39:08 +00:00
throw new RuntimeException("unreachable");
2009-05-16 08:01:07 +00:00
}
}));
2009-05-17 00:39:08 +00:00
System.out.println
("result: " +
callWithCurrentContinuation(new CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation) {
return 43;
}
}));
try {
callWithCurrentContinuation(new CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation) {
continuation.handleException(new MyException());
throw new RuntimeException("unreachable");
}
});
} catch (MyException e) {
e.printStackTrace();
}
try {
callWithCurrentContinuation(new CallbackReceiver<Integer>() {
public Integer receive(Callback<Integer> continuation)
throws MyException
{
throw new MyException();
}
});
} 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
}