Skip to content

Instantly share code, notes, and snippets.

@iamchiwon
Last active May 24, 2020 13:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iamchiwon/318af73e4239a3c9b787d29dbd1860b1 to your computer and use it in GitHub Desktop.
Save iamchiwon/318af73e4239a3c9b787d29dbd1860b1 to your computer and use it in GitHub Desktop.
RxSwift retry interval with condition
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) }
}
}
}
@iamchiwon
Copy link
Author

관련 포스팅
Rx.retryInterval

@iZoXia
Copy link

iZoXia commented Jan 17, 2020

Self.E is marked deprecated, Use self.Element instead. (since RxSwift 5.0.1, authored by freak4pc on 22 Apr 2019)

@iamchiwon
Copy link
Author

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