当我想在创建 Observable 后添加元素时,如何实现场景,可以完成吗?在观察者模式中,我只会触发事件左右。你有什么想法吗?
import rx.lang.scala._
val target = Observable(1,2,3,4)
val subscription1 = target subscribe(println(_))
val subscription2 = target subscribe(println(_))
def addToObservable(toAdd: Int, target: Observable[Int]): Observable[Int] = {
target/*.addElementAndNotifyObservers(toAdd)*/
}
addToObservable(4, target) //should print 4 on all subscriptions
addToObservable(6, target) //should print 6 on all subscriptions