如何向 PassthroughSubject 发送错误?
How do I send an error to a PassthroughSubject?
let myPassthrough = PassthroughSubject<String, Error>()
我知道我可以使用 send
:
向直通主题发送一个值
myPassthrough.send("abc")
发送失败怎么办?
我试过了:
myPassthrough.send(Fail(error: error))
myPassthrough.send(completion: Fail(error: error))
myPassthrough.send(completion: Just(error))
myPassthrough.send(completion: error)
None 编译
看起来 Subscribers.Completion
是一个枚举,所以这行得通:
myPassthrough.send(completion: .failure(error))
let myPassthrough = PassthroughSubject<String, Error>()
我知道我可以使用 send
:
myPassthrough.send("abc")
发送失败怎么办?
我试过了:
myPassthrough.send(Fail(error: error))
myPassthrough.send(completion: Fail(error: error))
myPassthrough.send(completion: Just(error))
myPassthrough.send(completion: error)
None 编译
看起来 Subscribers.Completion
是一个枚举,所以这行得通:
myPassthrough.send(completion: .failure(error))