Last active
February 25, 2019 11:25
-
-
Save iamchiwon/80bf93a799abbc40c7b86bc4563eaffe to your computer and use it in GitHub Desktop.
RxJava retry interval with condition
This file contains 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
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()) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
관련 포스팅
Rx.retryInterval