2009-05-16 08:01:07 +00:00
|
|
|
package extra;
|
|
|
|
|
|
|
|
import static avian.Continuations.callWithCurrentContinuation;
|
|
|
|
|
|
|
|
import avian.CallbackReceiver;
|
|
|
|
import avian.Callback;
|
|
|
|
|
|
|
|
public class Continuations {
|
2009-05-17 03:15:41 +00:00
|
|
|
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 {
|
2009-05-17 03:15:41 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
});
|
2009-05-17 03:15:41 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2009-05-17 03:15:41 +00:00
|
|
|
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
|
|
|
}
|