Last active
May 24, 2020 13:38
-
-
Save iamchiwon/318af73e4239a3c9b787d29dbd1860b1 to your computer and use it in GitHub Desktop.
RxSwift retry interval with condition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ObservableType { | |
public func retryInterval(_ intervals: [RxTimeInterval], when f: @escaping (Error) -> Bool) -> Observable<Self.Element> { | |
return retryWhen { error -> Observable<Int> in | |
error.flatMap { e -> Observable<Void> in | |
guard f(e) else { return .error(e) } | |
return .just(()) | |
} | |
.zip(with: Observable<RxTimeInterval>.from(intervals)) { $1 } | |
.flatMap { Observable<Int>.timer($0, scheduler: Schedulers.background) } | |
} | |
} | |
} |
Self.E is marked deprecated, Use self.Element instead. (since RxSwift 5.0.1, authored by freak4pc on 22 Apr 2019)
updated for RxSwift 5.0.1 (Thanks.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
관련 포스팅
Rx.retryInterval