This issue can be recreated by copying the below code into a playground. You will see that in the first example below the publisher is not released when using .flatMap with Fail
import Combine
import Foundation
struct SampleError: Error {}
weak var weakPublisher: CurrentValueSubjectSampleError, Never!
autoreleasepool {
let publisher = CurrentValueSubjectSampleError, Never(SampleError())
weakPublisher = publisher
publisher
.flatMap(FailVoid, SampleError.init(error:))
.sink(
receiveCompletion: { print("completed \($0)") },
receiveValue: { print("value \($0)") }
)
.cancel()
}
assert(weakPublisher == nil, "should be nil BUT IS NOT !!!")
In this second example, the publisher is released as expected using .tryMap with throw
import Combine
import Foundation
struct SampleError: Error {}
weak var weakPublisher2: CurrentValueSubjectSampleError, Never!
autoreleasepool {
let publisher = CurrentValueSubjectSampleError, Never(SampleError())
weakPublisher2 = publisher
publisher
.tryMap{ throw $0 }
.sink(
receiveCompletion: { print("completed \($0)") },
receiveValue: { print("value \($0)") }
)
.cancel()
}
assert(weakPublisher2 == nil, "is nil as expected")
Is this the expected behavior?
1
0
1.9k