New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mainThread() scheduler immediate mode #365
Comments
Can you just apply |
Thanks for the suggestion. I tried that, and can't get it to work. Possibly because my SampleRepository is actually a bit more complicated than I let on -- it returns the cached data (if available) but then concats a call to update with fresh data (my data source can't tell me if it has new data 😒 ). private LruCache<String, Data> mMemoryCache;
public Observable<Data> getData(final String key) {
return Observable.concat(getCachedData(key), requestFreshData(key));
}
private Observable<Data> requestFreshData (final String key) {
return api.getData(key);
}
private Observable<Data> getCachedData (final String key) {
final Data cachedData = mMemoryCache.get(key);
if (cachedData != null) {
return Observable.just(cachedData);
} else {
return Observable.empty();
}
} |
private Observable<Data> requestFreshData (final String key) {
return api.getData(key).observeOn(mainThread());
} |
Error:(119, 56) 错误: 不兼容的类型: io.reactivex.Scheduler无法转换为rx.Scheduler
|
@JakeWharton sorry I was off the grid for the long weekend. I published an example that (I think) demonstrates the problem. https://github.com/bishopmatthew/SynchronousSchedulerTest/ If you run it and rotate the device, you'll see a public Observable<Data> getData (final String key) {
return getCachedData(key)
.observeOn(Schedulers.io())
.concatWith(requestFreshData(key))
.observeOn(AndroidSchedulers.mainThread());
} Actually, I tried the
You can see the same thing if you put a breakpoint in my Fragment's subscription's Whereas if I don't do any
|
Replace public Observable<Data> getData (final String key) {
return getCachedData(key)
.observeOn(Schedulers.io())
.concatWith(requestFreshData(key))
.observeOn(AndroidSchedulers.mainThread());
} with public Observable<Data> getData (final String key) {
return getCachedData(key)
.concatWith(requestFreshData(key)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()));
} |
Wow it works! I swear I tried that. Er, I guess not with the nested |
I know this has been brought up before multiple times (#228, #335), but I'm still not sure what to do in my case and wondered if anyone had an idea.
I have some data I need to restore into a RecyclerView.Adapter synchronously (if available) before the view state gets restored in order to maintain scroll position.
I can't just leave off the
observeOn(AndroidSchedulers.mainThread()
becausesampleRepository.getData()
can either return a cached value from memory or a new value from the network. Any suggestions?The text was updated successfully, but these errors were encountered: