Thomas :
I have a Observable I want to repeat periodically, but only under a condition:
apiInterface.getData() // returns Observable<Data>
... // processing is happening here
.toList()
.repeatWhen(completed -> {
if (autoReload){
// Repeat every 3 seconds
return completed.delay(3, TimeUnit.SECONDS);
} else {
return ??? // What do I have to return that it does not repeat?
}
})
.subscribe(list -> callbackInterface.success(list));
My question is: What do I have to return in the else
statement to not repeat the Observable (just execute the chain once)?
akarnokd :
You have to react to the completion indicator by something that signals completion in response to an item, for example:
completed.takeWhile(v -> false);
Unfortunately, empty()
doesn't work there because it immediately completes the sequence before the source could even run.
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=466521&siteId=1