![](/img/trans.png)
[英]Is there a difference between doOnSuccess vs doOnNext for a Mono?
[英]RxJava: difference between doOnNext and doOnEach
在哪些情況下我應該使用doOnNext,在哪些情況下doOnEach?
.doOnEach(new Action1<Notification<? super MessageProfile>>() {
@Override
public void call(Notification<? super MessageProfile> notification) {
}
})
.doOnNext(new Action1<MessageProfile>() {
@Override
public void call(MessageProfile profile) {
messageProfileDao.save(profile);
}
})
這看起來兩個運算符具有相同的效果。
他們確實非常接近。 有一點不同(實際上在javadoc中可能沒有那么明確,在源代碼中更明顯)是在doOnEach中,您還會獲得錯誤和完成事件的Notification
包裝器。
然后,您可以檢查isOnNext
, isOnCompleted
或isOnError
以檢查您收到通知的實際事件類型。
所以一個Action.call
來統治它們,而不是一個完全成熟的Observer
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.