在哪些情况下我应该使用 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
关于java - RxJava : difference between doOnNext and doOnEach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28723341/