Hey,
I'm having an issue with the propagation of completion events on FlatMap publishers. If the mapped Publisher sends a failure
completion event, it will get send down the stream, but if the event is a finished
one, nothing happens.
Here's an example that reflects the issue:
enum SomeError: Error {
case someError
}
let trigger = PassthroughSubject<String, SomeError>()
let cancellable1 = trigger
.flatMap { _ in
Fail(error: SomeError.someError)
}
.sink(receiveCompletion: { completion in
print(completion)
}, receiveValue: { value in
print(value)
})
let cancellable2 = trigger
.flatMap { _ in
Empty<String, SomeError>()
}
.replaceEmpty(with: "empty")
.sink(receiveCompletion: { completion in
print(completion)
}, receiveValue: { value in
print(value)
})
trigger.send("")
The output of this is:
failure(__lldb_expr_80.SomeError.someError)
Is this the expecetd behavior? Or is there a bug on the FlatMap
publisher?