Fix crash in `.publisher()` caused by immediately cancelling subscriber (#66)
This commit is contained in:
parent
63dcea312f
commit
6158b9bdb3
|
@ -27,7 +27,6 @@ extension Defaults {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cancel() {
|
func cancel() {
|
||||||
observation?.invalidate()
|
|
||||||
observation = nil
|
observation = nil
|
||||||
subscriber = nil
|
subscriber = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -925,4 +925,20 @@ final class DefaultsTests: XCTestCase {
|
||||||
|
|
||||||
waitForExpectations(timeout: 10)
|
waitForExpectations(timeout: 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, iOSApplicationExtension 13.0, macOSApplicationExtension 10.15, tvOSApplicationExtension 13.0, watchOSApplicationExtension 6.0, *)
|
||||||
|
func testImmediatelyFinishingPublisherCombine() {
|
||||||
|
let key = Defaults.Key<Bool>("observeKey", default: false)
|
||||||
|
let expect = expectation(description: "Observation closure being called without crashing")
|
||||||
|
|
||||||
|
let cancellable = Defaults
|
||||||
|
.publisher(key, options: [.initial])
|
||||||
|
.first()
|
||||||
|
.sink { _ in
|
||||||
|
expect.fulfill()
|
||||||
|
}
|
||||||
|
|
||||||
|
cancellable.cancel()
|
||||||
|
waitForExpectations(timeout: 10)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue