Search in sources :

Example 1 with Tuple2

use of io.smallrye.mutiny.tuples.Tuple2 in project smallrye-mutiny by smallrye.

the class CombiningItemsTest method testWithMulti.

@Test
public void testWithMulti() throws InterruptedException {
    Multi<A> multiA = getMultiA();
    Multi<B> multiB = getMultiB();
    // tag::combine-multi[]
    Multi<Tuple2<A, B>> combined = Multi.createBy().combining().streams(multiA, multiB).asTuple();
    // end::combine-multi[]
    CountDownLatch latch = new CountDownLatch(1);
    AtomicInteger i = new AtomicInteger();
    combined.subscribe().with(tuple -> {
        int v = i.incrementAndGet();
        assertThat(tuple.getItem1()).isEqualTo("a" + v);
        assertThat(tuple.getItem2()).isEqualTo("b" + v);
    }, () -> latch.countDown());
    assertThat(latch.await(10, TimeUnit.MILLISECONDS)).isTrue();
    // tag::combine-multi-with[]
    Multi.createBy().combining().streams(multiA, multiB).using(list -> combineItems(list)).subscribe().with(x -> {
    // do something with the combined items
    });
// end::combine-multi-with[]
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tuple2(io.smallrye.mutiny.tuples.Tuple2) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

Tuple2 (io.smallrye.mutiny.tuples.Tuple2)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.jupiter.api.Test)1