Skip to content

Instantly share code, notes, and snippets.

@iamchiwon
Last active February 25, 2019 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamchiwon/80bf93a799abbc40c7b86bc4563eaffe to your computer and use it in GitHub Desktop.
Save iamchiwon/80bf93a799abbc40c7b86bc4563eaffe to your computer and use it in GitHub Desktop.
RxJava retry interval with condition
fun <T> Observable<T>.retryInterval(intervals: List<Long>, filter: (Throwable) -> Boolean): Observable<T> {
return this.retryWhen { throwable ->
throwable
.flatMap { e ->
if (!filter(e)) return@flatMap Observable.error<Throwable>(e)
return@flatMap Observable.just(e)
}
.zipWith(Observable.fromIterable(intervals)) { _, i -> i }
.flatMap { Observable.timer(it, TimeUnit.MILLISECONDS, Schedulers.newThread()) }
}
}
@iamchiwon
Copy link
Author

관련 포스팅
Rx.retryInterval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment