I am performing some tests to evaluate if there is a real advantage in using reactive API\'s based on Observables, instead of the blocking traditional ones.
The whole ex
The problem was caused by a programming error at some point. Actually the example in the question works perfectly.
One warning to prevent others from having problems: beware of using Observable.just(func)
, func is actually called on Observable creation. So any Thread.sleep placed there will block the calling thread
@Override
public Observable<List<Data>> loadDataObservable() {
return Observable.just(generateData()).delay(500, TimeUnit.MILLISECONDS);
}
private List<Data> generateData(){
List<Data> dataList = new ArrayList<Data>();
for (int i = 0; i < 20; i++) {
Data data = new Data("key"+i, "value"+i);
dataList.add(data);
}
return dataList;
}
I started a discussion in RxJava Google group where they helped me work it out.