我有2个正在连接的流。如果第一个流执行的是onError
而不是onComplete
,那么我不应该串联第二个流。
示例:
func updateEntity(entities: [Member]) -> Observable<[Result<Member>]> {
let remoteUpdate = remoteStore.update(entities: entities)
return remoteUpdate.concat(localStore.update(entities: entities))
}
如果localStore
抛出错误,则我不应该更新remoteUpdate
,在remoteUpdate
中调用onError
更新:
public override func update(entities: [PlaceAlert]) -> Observable<[Result<PlaceAlert>]> {
let remoteUpdate = remoteStore.update(entities: entities)
var entityPlaceHolder: [PlaceAlert] = entities
return remoteUpdate.catchError { _ in
entityPlaceHolder = []
return localStore.update(entities: entityPlaceHolder)
}.concat(localStore.update(entities: entityPlaceHolder))
}
只是尝试即兴创作。这会有所不同吗?出现错误
时,带有emptyArray的LocalUpdate不执行任何操作答案 0 :(得分:0)
concat
不是if / then语句。两个update
都在同一作用域被调用,只是如果remoteStore错误,结果将不会反映localStore.update响应。
catchError
是您想要的:
func updateEntity(entities: [Member]) -> Observable<[Result<Member>]> {
let remoteUpdate = remoteStore.update(entities: entities)
return remoteUpdate.catchError { _ in
localStore.update(entities: entities)
}
}