New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi.createBy().repeating() doesn't like flatMap #689
Comments
I ran this jbang script (forgive the ///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.smallrye.reactive:mutiny:1.0.0
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.infrastructure.Infrastructure;
public class mutli {
public static void main(String... args) {
AtomicLong line = new AtomicLong();
var count = Multi.createBy().repeating()
.supplier(line::incrementAndGet)
.until(l -> l.equals(1_000_000L))
.flatMap(l -> Multi.createFrom().item(l * 2))
.emitOn(Infrastructure.getDefaultExecutor())
.collect().with(Collectors.counting())
.await().indefinitely();
System.out.println(count);
System.out.println("Done");
}
} For a while I got:
And then I started to get errors so there is indeed a bug somewhere:
BTW may I ask why you want to await indefinitely? |
Just to be sure that all the Multi is fully processed, as I did not wanted to add test dependency for AssertSubscriber I've not looked into repeating() stuff, but I guess it's somewhere in it, as there is no Uni in the code. |
I've tried this and it fails after a random number of elements: AtomicLong line = new AtomicLong();
Multi.createBy().repeating()
.supplier(line::incrementAndGet)
.until(l -> l.equals(1_000_000L))
.flatMap(l -> Multi.createFrom().item(l * 2))
.emitOn(Infrastructure.getDefaultExecutor())
.subscribe().with(System.out::println, Throwable::printStackTrace); as in:
|
BTW you are not doing anything in parallel here, just the last bit of the pipeline. See https://smallrye.io/smallrye-mutiny/guides/emit-subscription |
Working on a fix |
Context
I've used Multi.createBy().repeating() for creating a Multi from an InputStream (read line by line).
Using Mutiny 1.0.0
Description
If I want to parallelize work on this Multi, I'm getting
java.lang.IllegalStateException: Invalid subscription state - already have a subscription for upstream
Additional details
Sample code :
The text was updated successfully, but these errors were encountered: