我是RxSwift的新手,我有以下问题。
给定两个函数:
struct Checkout { ... }
func getSessionIdOperation() -> Single<UUID>
func getCheckoutForSession(_ sessionId: UUID, asGuestUser: Bool) -> Single<Checkout>我有第三个函数,它结合了这两个函数的结果:
func getCheckout(asGuestUser: Bool) -> Single<Checkout> {
return getSessionIdOperation()
.map { ($0, asGuestUser) }
.flatMap(getCheckoutForSession)
}getSessionIdOperation和getCheckoutForSession都可能失败,如果失败,我只想重新启动整个链一次。我尝试过retry(2),但只是重复了一遍getCheckoutForSession。:(
发布于 2018-06-21 02:42:09
确保你使用flatMap retry(2) on stream
func getCheckout(asGuestUser: Bool) -> Single<Checkout> {
return getSessionIdOperation()
// .retry(2) will retry just first stream
.map { ($0, asGuestUser) }
.flatMap(getCheckoutForSession)
.retry(2) // Here it will retry whole stream
}如果getSessionIdOperation失败,getCheckoutForSession将永远不会被调用,因为它是基于第一个流的输出。
https://stackoverflow.com/questions/50843542
复制相似问题