记录一个小小测试结果
merge
将多个sequences 合并为一个sequence
let subject1 = PublishSubject<Int>()
let subject2 = PublishSubject<Int>()
Observable.of(subject1, subject2)
.merge()
.subscribe {
print($0)
}.addDisposableTo(disposeBag)
let e = myError()
subject1.onNext(10)
subject1.on(.next(10))
subject1.on(.next(11))
subject1.on(.next(12))
subject2.on(.next(20))
subject2.on(.next(21))
subject1.on(.next(14))
subject1.on(.error(e))// 只要出现error 所有流均终止
subject2.on(.next(22))
subject2.on(.completed)
输出结果:
next(10)
next(10)
next(11)
next(12)
next(20)
next(21)
next(14)
error(myError())
只要任意sequence 遇到error 就会中断所有sequence