Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatMap keeps its selector alive beyond inner observable completion #2605

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions Tests/RxSwiftTests/Observable+MergeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,33 @@ extension ObservableMergeTest {
Subscription(850, 950)
])
}


func testFlatMap_Complete_OuterNotComplete_DoesNotKeepSelectorAlive() {
let scheduler = TestScheduler(initialClock: 0)

let xs = scheduler.createHotObservable([
.next(100, 1),
.completed(200)
])

var object = Optional.some(TestObject())

let disposable = xs
.flatMap { [object] _ in
_ = object
return Observable<Never>.never()
}
.subscribe()
defer {
disposable.dispose()
}

weak var weakObject = object
object = nil

XCTAssertNil(weakObject)
}

func testFlatMap_Complete_ErrorOuter() {
let scheduler = TestScheduler(initialClock: 0)

Expand Down Expand Up @@ -2308,7 +2334,7 @@ extension ObservableMergeTest {
XCTAssertEqual(xs.recordedEvents[6].value.element!.subscriptions, [
])
}

func testFlatMap_SelectorThrows() {
let scheduler = TestScheduler(initialClock: 0)

Expand Down Expand Up @@ -3062,3 +3088,6 @@ extension ObservableMergeTest {
}
#endif
}

private class TestObject {
}