I have a Multi with items some of which are processed fast, but some of them are slow. What is the best way to let the fast items not be blocked by the slow ones. e.g. 'a' are fast and 'b' are slow
Multi.createFrom()
.items("a", "b","b","b","b","b","a","b","b","b","b", "a")
.onItem().transformToUniAndConcatenate(s -> s.equals("b") ? slow(s) : Uni.createFrom().item(s))
.subscribe()
.asStream()
.forEach(System.out::println);
private Uni<?> slow(String s) {
return Uni.createFrom()
.item(() -> {
try {Thread.sleep(5000);} catch (InterruptedException e) {e.printStackTrace();}
return s;
})
.runSubscriptionOn(Infrastructure.getDefaultWorkerPool());
}