//@Test
public void testFlatmapSendWithTimeoutsThreadToFiber() throws Exception {
final Channel<Integer> ch = newChannel();
Fiber fib = new Fiber("fiber", scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
assertThat(ch.receive(), is(1));
assertThat(ch.receive(30, TimeUnit.MILLISECONDS), is(nullValue()));
assertThat(ch.receive(40, TimeUnit.MILLISECONDS), is(20));
assertThat(ch.receive(), is(200));
assertThat(ch.receive(), is(2000));
assertThat(ch.receive(), is(40));
assertThat(ch.receive(), is(400));
assertThat(ch.receive(), is(4000));
assertThat(ch.receive(30, TimeUnit.MILLISECONDS), is(nullValue()));
assertThat(ch.receive(40, TimeUnit.MILLISECONDS), is(5));
assertThat(ch.receive(), is(nullValue()));
assertThat(ch.isClosed(), is(true));
}
}).start();
SendPort<Integer> ch1 = Channels.flatMapSend(Channels.<Integer>newChannel(1), ch, new Function<Integer, ReceivePort<Integer>>() {
@Override
public ReceivePort<Integer> apply(Integer x) {
if (x == 3)
return null;
if (x % 2 == 0)
return Channels.toReceivePort(Arrays.asList(new Integer[]{x * 10, x * 100, x * 1000}));
else
return Channels.singletonReceivePort(x);
}
});
Strand.sleep(50);
ch1.send(1);
Strand.sleep(50);
ch1.send(2);
ch1.send(3);
ch1.send(4);
Strand.sleep(50);
ch1.send(5);
ch1.close();
fib.join();
}