observableEmitingItemsRegularly
.map(this::cacheLastItem) //set the object in lastItem variable
.startWith(lastItem);
始终在开头返回相同的对象:解释该行时解释的值。
我已经尝试过:
改变
.startWith(lastItem);
与
.startWith(getLastItem());
函数 getLastItem()
是在我们初始化 observable 时调用的,而不是在我们按照我想要的方式订阅时调用的。
非常感谢!
最佳答案
您是否尝试过使用Defer
来自文档:
Defer do not create the Observable until the observer subscribes, and create a fresh Observable for each observer
.startWith(Observable.defer(() -> Observable.from(getLastItem()));
关于reactive-programming - 订阅时评估startwith的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32615567/