I m new to reactive programming and hence trying to learn.
I have 2 questions here.
- Is the below design using the Flux good ?
I have a flux
Flux<SomeClassObject> flx = Flux.from(Object of PublisherClass);
flx.map(otherClassObject -> {
Some function call, abc object creation and returned abc object
})
.doOnNext(this::someFunc) // someFunc that accepts object of type abc
.doOnError(e -> log.warn("warning",e);
.subscribe();
Class PublisherClass implements Publisher<abc class type>
{
private Subscriber<? super abc classtype> subscriber;
@Override
public void subscribe(Subscriber<? super PriceFetcherResponseWithRequest> subscriber) {
subscriber.onSubscribe(new BaseSubscriber() {
});
this.subscriber = subscriber;
}
void onComplete()
{
subscriber.onComplete();
}
void nextFunc()
{
subscriber.onNext(abc object); // this invokes the map in the above flux, which in turn calls doOnNext some func
}
}
The main thread calls flx.subscribe. which internally stores the subscriber object in publisher class. and then the main thread calls the nextFunc() (in a loop and finally calls onComplete, which internally calls flux onComplete) in publisherClass which inturn calls the onNext whch will invoke the .map effect in the flux, and then doOnNext someFunc is called.
Is this a bad design to use flux as the calling thread itself in invoking the onNext, map effect and doOnNext ??
- What would be a better design to replace the publisher class with a flux and make both these flux interdependent?
like say Flux.fromIterable and on the map effect it can call the subscriber.onNext of the first flux flx.
The main thread will have to subscribe on both the flux.
Is there any other better way to do this ? will it be okay to subscribeOn a scheduler for both these flux ? so that both these flux execute on different threads apart from main.
I am new to reactive and just started learning since a week. Kindly dont mind if i am asking something naive.
Any input is appreciated.