22
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

Senseful
  • 86,719
  • 67
  • 308
  • 465

1 Answers1

46

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

myPassthrough.send(completion: .failure(error))
Senseful
  • 86,719
  • 67
  • 308
  • 465