RxJava2:按条件重复/不要在“ repeatWhen”中重复

Tho*_*mas 6 java android reactive-programming rx-java rx-java2

我有一个Observable,我想定期重复,但仅限以下情况:

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));
Run Code Online (Sandbox Code Playgroud)

我的问题是:我必须在else语句中返回什么才能不重复Observable(只需执行一次链)?

aka*_*okd 7

您必须通过对项目做出响应的某种方式来响应完成指示符,例如:

completed.takeWhile(v -> false);
Run Code Online (Sandbox Code Playgroud)

不幸的是,empty()它在那里不起作用,因为它会立即完成序列,甚至无法运行源。