http://blog.danlew.net/2015/07/23/deferring-observable-code-until-subscription-in-rxjava/ discusses creating observables using Observable.just, Observable.create, and Observable.defer
Let's say I have this:
List<File> fileIOFunction() {
// does some file io operations
}
OBSERVABLE.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
What thread do the file io operations run on if OBSERVABLE is:
Observable.create(
new Observable.OnSubscribe<List<File>>() {
@Override
public void call(Subscriber<? super List<File>>
subscriber) {
subscriber.onNext(fileIOFunction());
}
If OBSERVABLE is Observable.just(fileIOFunction())
If OBSERVABLE is
Observable.defer(new Func0<Observable<List<File>>>() {
@Override
public Observable<List<File>> call() {
return Observable.just(fileIOFunction());
});
System.out.println(Thread.currentThread())tofileIOFunction(), implement both cases and run them. - akarnokd