-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Description
An issue was filed on RxAndroid asking for the default "main thread" scheduler to be lazily initialized. This would allow support for unit testing on the JVM by swapping out the scheduler for one that works where Android's main thread doesn't exist.
The hook API provides a means of replacing the scheduler during initialization, but the problem is that in order to call these "init" methods the instance needs to be eagerly created.
What I'm proposing is that we change the "init" functions from Function<Scheduler, Scheduler> to Function<Scheduler, Callable<Scheduler>> which would allow ignoring the default scheduler instance by never delegating to Callable.call() to create it.
The implementation of the initializer would change to something like:
Scheduler initFoo(Callable<Scheduler> defaultScheduler);
Function f = initFunc;
if (f == null) {
return defaultScheduler.call();
}
return apply(f, defaultScheduler);Now we can make this change only in RxAndroid to support this case. I think that there's a large value in having as much symmetry between the two libraries as possible, however.
Is this something that would be acceptable to change in RxJava? Or are there any alternative APIs that anyone can think of for this?