rx-java2

RxJava2 - interval and schedulers

心已入冬 提交于 2021-01-28 18:58:43
问题 Let's say I have an interval, and that I've given it a computationScheduler. Like this: Observable .interval(0, 1, TimeUnit.SECONDS, computationScheduler) .flatMap { ... } Then, will everything that happens in flatmap {...} also be scheduled on a computation thread? In the sources for Observable.interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler), it says: * @param scheduler * the Scheduler on which the waiting happens and items are emitted As a beginner to RxJava, I

RxJava: how do you flush a timed buffer?

ⅰ亾dé卋堺 提交于 2021-01-28 08:46:00
问题 I'm creating this PublishProcessor that save to the database its element every 10 seconds: val publishProcessor = PublishProcessor.create<Entity>() publishProcessor .buffer(10, SECONDS) .observeOn(Schedulers.io()) .subscribe( { saveToDatabase(it) }, { Log.e("TAG", "Error: $it") }) .addTo(compositeDisposable) When my activity finish, I want to flush everything that is in the current buffer, and not wait 10 seconds. How do I do that? 回答1: Have another subject as the buffer boundary that is

Am I using flatMap correctly to merge results from multiple API calls?

点点圈 提交于 2021-01-28 08:19:04
问题 I want to make multiple API calls (with three different queries) and merge the results and then display them in onNext() . It is working but I am concerned that flatMap is not ideal for this. @GET("www.examle.com/api/data/") Observable<WebResultsResponse> getWebResults(@Query("param1") String query); ----- private List<WebResult> resultsList; private void requestWebResults(String query) { resultsList.clear(); final Observable<List<WebResult>> observable = MainApplication.apiProvider

RxJava: how to handle combineLatest() when one of the streams emits nothing

痞子三分冷 提交于 2021-01-27 13:21:08
问题 I use combineLatest() to combine 3 streams of observables. All these are combined so that all data in the UI is shown at the same time. Now, there is a scenario in which one of the observables won't emit anything, since the data that gets fetched, can be null. Is there a RxJava operator to let the subscriber know that there won't be any emits because of null data? Edit private fun retrieveData() { Observable.combineLatest(getCurrentUser.execute(), getLatestGoal.execute(), getLatestLog.execute

Transfer Encoding chunked with okhttp only delivers full result

喜你入骨 提交于 2021-01-27 04:42:12
问题 I am trying to get some insights on a chunked endpoint and therefore planned to print what the server sends me chunk by chunk. I failed to do so so I wrote a test to see if OkHttp/Retrofit are working as I expect it. The following test should deliver some chunks to the console but all I get is the full response. I am a bit lost what I am missing to even make the MockWebServer of OkHttp3 sending me chunks. I found this retrofit issue entry but the answer is a bit ambiguous for me: Chunked

How to get value from LiveData synchronously?

青春壹個敷衍的年華 提交于 2021-01-21 07:45:06
问题 For LiveData , is there something similar to blockingNext or blockingSingle in RxJava's Observable to get the value synchronously? if not, how can i achieve the same behavior? 回答1: You can call getValue() to return the current value, if there is one. However, there is no "block until there is a value" option. Mostly, that is because LiveData is meant to be consumed on the main application thread, where indefinitely-blocking calls are to be avoided. If you need "block until there is a value",

How to get value from LiveData synchronously?

只谈情不闲聊 提交于 2021-01-21 07:44:07
问题 For LiveData , is there something similar to blockingNext or blockingSingle in RxJava's Observable to get the value synchronously? if not, how can i achieve the same behavior? 回答1: You can call getValue() to return the current value, if there is one. However, there is no "block until there is a value" option. Mostly, that is because LiveData is meant to be consumed on the main application thread, where indefinitely-blocking calls are to be avoided. If you need "block until there is a value",

Android Room inserts duplicate entities

半城伤御伤魂 提交于 2020-12-29 06:12:15
问题 I'm using Android's Room library for the database interaction in an application and I'm sort of stumped on how to prevent duplicate entries from being inserted into the database. I feel like I must be missing something because this seems like it should be simple to do. I've searched Google for various combinations of words relating to the subject to no avail. I'm essentially using what one of the samples does for inserting and querying. The Entity: @Entity(tableName = "cameras") public class

Paging3: “Not sure how to convert a Cursor to this method's return type” when using PagingSource as return type in Room DAO

对着背影说爱祢 提交于 2020-12-05 07:28:29
问题 I was trying to imitate Google's codelab for the new Paging 3 library, and I encountered the following error when I tried to have a Room DAO method return a PagingSource : D:\Programming\Android\something\app\build\tmp\kapt3\stubs\debug\com\someapp\something\data\db\UsersDao.java:38: error: Not sure how to convert a Cursor to this method's return type (androidx.paging.PagingSource<java.lang.Integer,com.someapp.something.data.db.GithubUser>). public abstract androidx.paging.PagingSource<java