-
Hello! if I run the following test, it is green but Mutiny logs Is there a way to properly cancel other Unis if the first one was already received, so that no dropped exceptions are reported? It seems that it happens only if the unis run on an executor. Thanks! The test: import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.infrastructure.Infrastructure;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
class UniFirstTest {
@Test
void uni() throws Exception {
var bean = new Bean();
Uni<String> a = Uni.createFrom().item(() -> bean.getValue("f")).runSubscriptionOn(Infrastructure.getDefaultWorkerPool());
Uni<String> b = Uni.createFrom().item(() -> bean.getValue("test")).runSubscriptionOn(Infrastructure.getDefaultWorkerPool());
var subscribe = Uni.join().first(a, b).withItem().subscribe();
assertThat(subscribe.asCompletionStage().get(10, TimeUnit.SECONDS)).isEqualTo("testtest");
}
private static class Bean {
public String getValue(String test) {
if (test == null || test.length() < 3) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
throw new IllegalArgumentException("too short");
}
return test + test;
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
What you are seeing here is actually normal, the upstream If you want to run some code that can either emit an item or report an exception, you might use |
Beta Was this translation helpful? Give feedback.
UniJoinFirst
actually cancels the remainingUni
instances when the first one emits an item.What you are seeing here is actually normal, the upstream
Uni
is running (blocking) code ingetValue
. So ultimately an exception is thrown after cancellation, and this is still being reported because creating from an item should not throw, and because the code ingetValue
has no way to cancel (Mutiny cannot automagically cancel code).If you want to run some code that can either emit an item or report an exception, you might use
Uni.createFrom().emitter(...)
.