RxSwiftExt
RxSwiftExt copied to clipboard
Cascade does not complete if the last observable completes immediately and synchronously
Hi everyone,
I'm using the cascade operator in many kinds of scenarios and I'm very grateful for it.
There is an issue though, when for some reason the last observable completes immediately (i.e. in a synchronous manner), the resulting cascading observable will not complete.
I believe that is because of the if initialized test when subscribing to underlying observables: https://github.com/RxSwiftCommunity/RxSwiftExt/blob/master/Source/RxSwift/cascade.swift#L57
For example, if the last observable in the list is a .just(whatever), the cascade will never complete.
It looks like it's a regression that was introduced with commit https://github.com/RxSwiftCommunity/RxSwiftExt/commit/4ba2dd68934fd0915012ed74d89a9c5a144da7e1
The following test can help understand the issue (it's red at the moment):
func testSynchronousCompletion() {
let xs = scheduler.createHotObservable([
.next(110, 1),
.next(180, 2),
.next(230, 3),
.next(270, 4),
.next(340, 5),
.completed(200)
])
.asObservable()
let ys = scheduler.createHotObservable([
.next(100, 21),
.completed(210, Int.self)
])
.asObservable()
let zs = Observable<Int>.just(31)
let res = scheduler.start { () -> Observable<Int> in
Observable.cascade([xs, ys, zs])
}
XCTAssertEqual(res.events, [
.next(200, 31),
.completed(200)
]) // <--- it's just `[.next(200, 31)`
}
Hey :) I'm not too knowledgable with this operator - but since that commit is over 2 years old, I wouldn't want to change the behavior without being positive about this.
@fpillet could you comment ?
Ouch, the latest commit was there to harden Cascade, not weaken it. Thanks for the detailed error case, I'll fix it.
Thanks so much @fpillet!