-
|
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: 2 comments 6 replies
-
|
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.
-
|
Hey, I have two api calls and am sure only either of the calls will succeed or both will fail. If both fail I'm interested to see the underlying logs. But since both calls now emit an item, I have to always await both calls even though the first call might have technically succeeded. I hope it's clear, I can also write an example! Thanks a lot! |
Beta Was this translation helpful? Give feedback.
UniJoinFirstactually cancels the remainingUniinstances when the first one emits an item.What you are seeing here is actually normal, the upstream
Uniis 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 ingetValuehas 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(...).