I started learning java reactor 3. The following code can't output any results.
Flux.create(sink -> {
sink.next("produce a number: " + Math.random() * 100);
// sink.complete();
}).publishOn(Schedulers.elastic())
.subscribe(
consumer -> System.out.println(Thread.currentThread().getName() + consumer),
error -> System.out.println("error!" + error),
() -> {
System.out.println("task complete!");
});
You have to block main()
until user input System.in.read();
. Just after this subscribe()
! Your problem that you app exits earlier than an execution happens in your Flux
.