RxJavaGuava icon indicating copy to clipboard operation
RxJavaGuava copied to clipboard

Requirement for Scheduler

Open benjchristensen opened this issue 9 years ago • 4 comments

Right now the API requires defining a Scheduler. Why is that required?

I see two possible defaults:

  1. It just runs on the thread ListenableFuture calls back on
  2. It can be scheduled on Scheduler.computation() by default

I think (1) is the correct default. Someone can use observeOn if they want to move the scheduling. Thus, I don't fully understand why Scheduler even needs to be passed in.

benjchristensen avatar Jun 05 '15 15:06 benjchristensen

cc @abersnaze

benjchristensen avatar Jun 05 '15 15:06 benjchristensen

The API for a ListenableFuture requires you to specify the Executor to schedule the completion callback on. By not adding one in version 1 left it open for adding a overload in the future. Is there is a reasonable default Scheduler/Executor?

abersnaze avatar Jun 05 '15 17:06 abersnaze

Well that's an awkward callback then. It means it always gets scheduled. Annoying.

I would default to computation like everything else does since this is pure compute, no IO for emitting the result.

benjchristensen avatar Jun 05 '15 19:06 benjchristensen

Hi @benjchristensen, @abersnaze

Just as a follow up on this, would it be OK to have the following:

public static <T> Observable<T> from(final ListenableFuture<T> future) {
    from(future, Schedulers.computation());
}

and then use

ListenableFutureObservable.from(myFuture)
    .observeOn(Schedulers.io());

I'm asking for a use in the Cassandra driver context which returns a guava ListenableFuture. I'm still struggling to understand what the real impact of using a scheduler or an other and how the processing switches from one thread to another. In my use case I guess I could just use from(cassandraFuture, Schedulers.io()) but i'd like to understand a bit more what i'm doing with this.

Thanks

Crystark avatar Feb 26 '16 09:02 Crystark