I'm currently implementing a small subset of RxJava2's API for a personal project. I have a listener-based API and I started writing the code to wrap my listener and implementing Flowable.create()
:
public class EventBus {
private final Flowable<Event> events;
public EventBus(MyApi api) {
this.events = Flowable.create(emitter -> {
Callback listener = new Callback() {
@Override
public void onEvent(Event event) {
emitter.onNext(event);
}
};
api.addListener(listener);
// TODO api.removeListener(listener)
}, BackpressureStrategy.BUFFER);
}
}.
I ran a quick test and it worked just fine, but I realized it is single threaded. No biggie: it is actually RxJava's design to be single threaded unless specifying a Scheduler
.
Per RxJava2's documentation, I decided to chain a Flowable.subscribeOn()
call, which I will call with a Scheduler.computation()
argument.
So I moved on to implementing Flowable.subscribeOn()
and Scheduler.computation()
, and this is where I'm trying to wrap my head around: I've seen in various places that Java's ForkJoinPool.commonPool()
is recommended to run computation tasks on, But RxJava2 doesn't use it. My main questions would be:
- Would this be a good fit for my very basic reactive implementation?
- Why did RxJava2 choose to implement its own pool instead of using this one?
- Are there any problems with this approach that I should be aware of to make my life easier down the road?
Thanks!