topic.subscribe(channel1);
topic.subscribe(channel2);
topic.subscribe(channel3);
Fiber f1 = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
assertThat(channel1.receive(), equalTo("hello"));
assertThat(channel1.receive(), equalTo("world!"));
}
}).start();
Fiber f2 = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
assertThat(channel2.receive(), equalTo("hello"));
assertThat(channel2.receive(), equalTo("world!"));
}
}).start();
Fiber f3 = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
assertThat(channel3.receive(), equalTo("hello"));
assertThat(channel3.receive(), equalTo("world!"));
}
}).start();
Thread.sleep(100);
topic.send("hello");
Thread.sleep(100);
topic.send("world!");
f1.join();
f2.join();
f3.join();
}