我目前正在尝试使用Java中的反应式扩展来实现特定的结果,但是我无法做到这一点,也许你们中的某人可以帮助我。
firstCompletable .onErrorComplete(t -> specificErrorHandlingOne()) .andThen(secondCompletable()) .onErrorComplete(t -> specificErrorHandlingTwo()) .andThen(thirdCompletable()) .onErrorComplete(t -> specificErrorHandlingThree()) .andThen(fourthCompletable()) .onErrorComplete(t -> specificErrorHandlingFour()) .subscribe(viewCallback::showSuccess)
但是,例如在secondCompletable中存在错误时,将执行特定的错误处理,但随后仍在计划其他Completable。我希望如果其中一个Completables失败,整个Completables链将停止执行。我该怎么做?
我已经尝试过使用doOnError代替,但这只是在没有抛出特定错误的堆栈跟踪中结束。
Completable.concat( completable1.doOnError(e -> {...}), completable2.doOnError(e -> {...}), completable3.doOnError(e -> {...}), completable4.doOnError(e -> {...}) ).subscribe(action, errorConsumer);
完成项将按指定顺序进行订阅
action
will be invoked when all complete
You can specify error handlers for each one (this is optional)
Any error will break the pipeline and propagate to subscriber (errorConsumer
)
Your original andThen
chain shall also work but you need to replace onErrorComplete
, which substitutes an error with completion, with doOnError
, which just invokes specified action. Or just return false
from your specificErrorHandlingXxx()
.