@Test public void broadcastThreads() throws InterruptedException { Topic<Integer> topic = ReactiveSeq.range(0,100_000) .broadcast(); Thread t= new Thread( ()-> { ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream2.takeRight(1).singleOrElse(-1), equalTo(99_999)); }); t.start(); ReactiveSeq<Integer> stream1 = topic.stream(); assertThat(stream1.takeRight(1).singleOrElse(-1),equalTo(99_999)); t.join(); }
@Test public void broadcastThreads() throws InterruptedException { Topic<Integer> topic = Spouts.range(0,100_000) .broadcast(); Thread t= new Thread( ()-> { ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream2.takeRight(1).singleOrElse(null), Matchers.equalTo(99_999)); }); Thread t2 = new Thread( ()->{ ReactiveSeq<Integer> stream1 = topic.stream(); assertThat(stream1.takeRight(1).singleOrElse(null), Matchers.equalTo(99_999)); }); t.start(); t2.start(); t.join(); t2.join(); }
@Test public void broadcastTest(){ Topic<Integer> topic = Spouts.of(1,2,3) .broadcast(); ReactiveSeq<Integer> stream1 = topic.stream(); ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream1.toList(), Matchers.equalTo(Arrays.asList(1,2,3))); assertThat(stream2.toList(), Matchers.equalTo(Arrays.asList(1,2,3))); } @Test
@Test public void broadcastTest(){ Topic<Integer> topic = ReactiveSeq.of(1,2,3) .broadcast(); ReactiveSeq<Integer> stream1 = topic.stream(); ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream1.toList(),equalTo(Arrays.asList(1,2,3))); assertThat(stream2.stream().toList(),equalTo(Arrays.asList(1,2,3))); } @Test
@Test public void broadcastTest(){ Topic<Integer> topic = of(1,2,3) .broadcast(); ReactiveSeq<Integer> stream1 = topic.stream(); ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream1.toList(), Matchers.equalTo(Arrays.asList(1,2,3))); assertThat(stream2.stream().toList(), Matchers.equalTo(Arrays.asList(1,2,3))); } @Test
@Test public void broadcastTest() { Topic<Integer> topic = of(1, 2, 3) .broadcast(); ReactiveSeq<Integer> stream1 = topic.stream(); ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream1.toList(), Matchers.equalTo(Arrays.asList(1, 2, 3))); assertThat(stream2.stream().toList(), Matchers.equalTo(Arrays.asList(1, 2, 3))); }
@Test public void broadcastTest(){ Topic<Integer> topic = of(1,2,3) .broadcast(); ReactiveSeq<Integer> stream1 = topic.stream(); ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream1.toList(), Matchers.equalTo(Arrays.asList(1,2,3))); assertThat(stream2.stream().toList(), Matchers.equalTo(Arrays.asList(1,2,3))); } @Test
@Test public void broadcastTest(){ Topic<Integer> topic = of(1,2,3) .broadcast(); ReactiveSeq<Integer> stream1 = topic.stream(); ReactiveSeq<Integer> stream2 = topic.stream(); assertThat(stream1.toList(), Matchers.equalTo(Arrays.asList(1,2,3))); assertThat(stream2.stream().toList(), Matchers.equalTo(Arrays.asList(1,2,3))); } @Test
/** * Create a pushable JDK 8 Stream * @return a Tuple2 with a Topic<T> and Stream<T> - add data to the Queue * to push it to the Stream */ public Stream<T> stream() { return topic.stream(); }
/** * Create a pushable {@link ReactiveSeq} * * @return a Tuple2 with a Topic<T> and Seq<T> - add data to the Queue * to push it to the Stream */ public ReactiveSeq<T> reactiveSeq() { return topic.stream(); }
/** * Create a pushable LazyFutureStream using the supplied ReactPool * * @param s React builder to use to create the Stream * @return a Tuple2 with a Topic<T> and LazyFutureStream<T> - add data to the Queue * to push it to the Stream */ public FutureStream<T> futureStream(final LazyReact s) { return s.fromStream(topic.stream()); }