Making withLatestFrom subscribe to the right hand side first

This resolves an issue where you have two observables that yield values
immediately and it wasn't yielding a result
This commit is contained in:
Mike Lewis 2015-11-17 14:37:19 -08:00
parent c909f0f572
commit 7ade18ba75
2 changed files with 19 additions and 1 deletions

View File

@ -32,8 +32,8 @@ class WithLatestFromSink<FirstType, SecondType, ResultType, O: ObserverType wher
let sndSubscription = SingleAssignmentDisposable()
let sndO = WithLatestFromSecond(parent: self, disposable: sndSubscription)
let fstSubscription = _parent._first.subscribe(self)
sndSubscription.disposable = _parent._second.subscribe(sndO)
let fstSubscription = _parent._first.subscribe(self)
return StableCompositeDisposable.create(fstSubscription, sndSubscription)
}

View File

@ -4293,6 +4293,24 @@ extension ObservableMultipleTest {
])
}
func testWithLatestFrom_TwoObservablesWithImmediateValues() {
let xs = BehaviorSubject<Int>(value: 3)
let ys = BehaviorSubject<Int>(value: 5)
let scheduler = TestScheduler(initialClock: 0)
let res = scheduler.start {
xs.withLatestFrom(ys) { x, y in "\(x)\(y)" }
.take(1)
}
XCTAssertEqual(res.messages, [
next(200, "35"),
completed(200)
])
}
func testWithLatestFrom_Simple2() {
let scheduler = TestScheduler(initialClock: 0)