io.smallrye.mutiny.groups.UniAndGroup5 Maven / Gradle / Ivy
package io.smallrye.mutiny.groups;
import static io.smallrye.mutiny.helpers.ParameterValidation.nonNull;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import io.smallrye.mutiny.shaded.io.smallrye.common.annotation.CheckReturnValue;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import io.smallrye.mutiny.tuples.Functions;
import io.smallrye.mutiny.tuples.Tuple5;
import io.smallrye.mutiny.tuples.Tuples;
public class UniAndGroup5 extends UniAndGroupIterable {
public UniAndGroup5(Uni extends T1> source, Uni extends T2> o1, Uni extends T3> o2,
Uni extends T4> o3, Uni extends T5> o4) {
super(source, Arrays.asList(o1, o2, o3, o4));
}
@CheckReturnValue
public UniAndGroup5 collectFailures() {
super.collectFailures();
return this;
}
@CheckReturnValue
public Uni> asTuple() {
return combine(Tuple5::of);
}
/**
* Limit the number of concurrent upstream subscriptions.
*
* When not specified all upstream {@link Uni} are being subscribed when the combining {@link Uni} is subscribed.
*
* Setting a limit is useful when you have a large number of {@link Uni} to combine and their simultaneous
* subscriptions might overwhelm resources (e.g., database connections, etc).
*
* @param level the concurrency level, must be strictly positive
* @return an object to configure the combination logic
*/
@CheckReturnValue
public UniAndGroup5 usingConcurrencyOf(int level) {
super.usingConcurrencyOf(level);
return this;
}
/**
* @deprecated use {@link #with(Functions.Function5)} instead
*/
@Deprecated(forRemoval = true)
@CheckReturnValue
public Uni combinedWith(Functions.Function5 combinator) {
return with(combinator);
}
@CheckReturnValue
public Uni with(Functions.Function5 combinator) {
Functions.Function5 actual = Infrastructure
.decorate(nonNull(combinator, "combinator"));
return combine(actual);
}
@SuppressWarnings("unchecked")
private Uni combine(Functions.Function5 combinator) {
Function, O> function = list -> {
Tuples.ensureArity(list, 5);
T1 item1 = (T1) list.get(0);
T2 item2 = (T2) list.get(1);
T3 item3 = (T3) list.get(2);
T4 item4 = (T4) list.get(3);
T5 item5 = (T5) list.get(4);
return combinator.apply(item1, item2, item3, item4, item5);
};
return super.with(function);
}
@CheckReturnValue
public Uni withUni(Functions.Function5> combinator) {
Functions.Function5> actual = Infrastructure
.decorate(nonNull(combinator, "combinator"));
return combineUni(actual);
}
@SuppressWarnings("unchecked")
private Uni combineUni(Functions.Function5> combinator) {
Function, Uni> function = list -> {
Tuples.ensureArity(list, 5);
T1 item1 = (T1) list.get(0);
T2 item2 = (T2) list.get(1);
T3 item3 = (T3) list.get(2);
T4 item4 = (T4) list.get(3);
T5 item5 = (T5) list.get(4);
return combinator.apply(item1, item2, item3, item4, item5);
};
return super.with(function).flatMap(Function.identity());
}
}