How do I send an error to a PassthroughSubject?

Viewed 4360
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

1 Answers

Looks like Subscribers.Completion is an enum, so this works:

myPassthrough.send(completion: .failure(error))
Related