let myPassthrough = PassthroughSubject<String, Error>()
I know I can send a value to a passthrough subject using send
:
myPassthrough.send("abc")
How do I send a failure?
I tried:
myPassthrough.send(Fail(error: error))
myPassthrough.send(completion: Fail(error: error))
myPassthrough.send(completion: Just(error))
myPassthrough.send(completion: error)
None of them compile
A subject that broadcasts elements to downstream subscribers. As a concrete implementation of Subject, the PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model.
As a concrete implementation of Subject, the PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model. Unlike CurrentValueSubject, a PassthroughSubject doesn’t have an initial value or a buffer of the most recently-published element.
PassthroughSubjectcan easily be used in place of a delegate pattern, or to convert an existing delegate pattern to Combine.
We are now able to satisfy the constraint of 1.03 even if the DispatchQueue is concurrent or the OperationQueue is not a restriction of maxConcurrentOperations of 1, or for that matter any valid scheduler being concurrent; we will always send serialized events on that requested scheduler for .receive (on:).
Looks like Subscribers.Completion
is an enum, so this works:
myPassthrough.send(completion: .failure(error))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With