2009-05-26 05:30:40 +00:00
|
|
|
package extra;
|
|
|
|
|
2009-05-16 08:01:07 +00:00
|
|
|
import static avian.Continuations.callWithCurrentContinuation;
|
|
|
|
|
2014-03-21 13:33:50 +00:00
|
|
|
import avian.Function;
|
2009-05-16 08:01:07 +00:00
|
|
|
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 {
|
2014-03-21 13:33:50 +00:00
|
|
|
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 {
|
2014-03-21 13:33:50 +00:00
|
|
|
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 {
|
2014-03-21 13:33:50 +00:00
|
|
|
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
|
|
|
}
|