mirror of
https://github.com/corda/corda.git
synced 2025-01-23 04:48:09 +00:00
move Continuations and Coroutines tests to top-level test directory
This commit is contained in:
parent
e35047b056
commit
db91c27441
@ -1,5 +1,3 @@
|
|||||||
package extra;
|
|
||||||
|
|
||||||
import static avian.Continuations.callWithCurrentContinuation;
|
import static avian.Continuations.callWithCurrentContinuation;
|
||||||
|
|
||||||
import avian.CallbackReceiver;
|
import avian.CallbackReceiver;
|
@ -1,5 +1,3 @@
|
|||||||
package extra;
|
|
||||||
|
|
||||||
import static avian.Continuations.callWithCurrentContinuation;
|
import static avian.Continuations.callWithCurrentContinuation;
|
||||||
|
|
||||||
import avian.CallbackReceiver;
|
import avian.CallbackReceiver;
|
||||||
@ -11,15 +9,28 @@ public class Coroutines {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void produce(Consumer<Character> consumer) throws Exception {
|
private static void produce(Consumer<Character> consumer) throws Exception {
|
||||||
|
System.out.println("produce \"a\"");
|
||||||
consumer.consume('a');
|
consumer.consume('a');
|
||||||
|
|
||||||
|
System.out.println("produce \"b\"");
|
||||||
consumer.consume('b');
|
consumer.consume('b');
|
||||||
|
|
||||||
|
System.out.println("produce \"c\"");
|
||||||
consumer.consume('c');
|
consumer.consume('c');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void consume(Producer<Character> producer) throws Exception {
|
private static void consume(Producer<Character> producer) throws Exception {
|
||||||
expect(producer.produce() == 'a');
|
char v = producer.produce();
|
||||||
expect(producer.produce() == 'b');
|
System.out.println("consume \"" + v + "\"");
|
||||||
expect(producer.produce() == 'c');
|
expect(v == 'a');
|
||||||
|
|
||||||
|
v = producer.produce();
|
||||||
|
System.out.println("consume \"" + v + "\"");
|
||||||
|
expect(v == 'b');
|
||||||
|
|
||||||
|
v = producer.produce();
|
||||||
|
System.out.println("consume \"" + v + "\"");
|
||||||
|
expect(v == 'c');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
@ -28,30 +39,10 @@ public class Coroutines {
|
|||||||
final Consumer<Character> consumer = new Consumer<Character>() {
|
final Consumer<Character> consumer = new Consumer<Character>() {
|
||||||
public void consume(final Character c) throws Exception {
|
public void consume(final Character c) throws Exception {
|
||||||
callWithCurrentContinuation(new CallbackReceiver() {
|
callWithCurrentContinuation(new CallbackReceiver() {
|
||||||
public Object receive(Callback continuation) {
|
public Object receive(Callback continuation) {
|
||||||
state.produceNext = continuation;
|
state.produceNext = continuation;
|
||||||
|
|
||||||
state.consumeNext.handleResult(c);
|
state.consumeNext.handleResult(c);
|
||||||
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final Producer<Character> producer = new Producer<Character>() {
|
|
||||||
public Character produce() throws Exception {
|
|
||||||
return callWithCurrentContinuation(new CallbackReceiver<Character>() {
|
|
||||||
public Character receive(Callback<Character> continuation)
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
state.consumeNext = continuation;
|
|
||||||
|
|
||||||
if (state.produceNext == null) {
|
|
||||||
Coroutines.produce(consumer);
|
|
||||||
} else {
|
|
||||||
state.produceNext.handleResult(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@ -59,6 +50,29 @@ public class Coroutines {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
final Producer<Character> producer = new Producer<Character>() {
|
||||||
|
final CallbackReceiver<Character> receiver
|
||||||
|
= new CallbackReceiver<Character>() {
|
||||||
|
public Character receive(Callback<Character> continuation)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
state.consumeNext = continuation;
|
||||||
|
|
||||||
|
if (state.produceNext == null) {
|
||||||
|
Coroutines.produce(consumer);
|
||||||
|
} else {
|
||||||
|
state.produceNext.handleResult(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public Character produce() throws Exception {
|
||||||
|
return callWithCurrentContinuation(receiver);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
consume(producer);
|
consume(producer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user