Remove newThread usages, it probably fixes random crashes

This commit is contained in:
len
2016-07-08 18:23:03 +02:00
parent f15df40a54
commit 5f1a89df63
4 changed files with 8 additions and 7 deletions

View File

@@ -1,12 +1,15 @@
package eu.kanade.tachiyomi.util
import rx.Observable
import rx.Scheduler
import rx.functions.Func1
import rx.schedulers.Schedulers
import java.util.concurrent.TimeUnit.MILLISECONDS
class RetryWithDelay(
private val maxRetries: Int = 1,
private val retryStrategy: (Int) -> Int = { 1000 }
private val retryStrategy: (Int) -> Int = { 1000 },
private val scheduler: Scheduler = Schedulers.computation()
) : Func1<Observable<out Throwable>, Observable<*>> {
private var retryCount = 0
@@ -14,7 +17,7 @@ class RetryWithDelay(
override fun call(attempts: Observable<out Throwable>) = attempts.flatMap { error ->
val count = ++retryCount
if (count <= maxRetries) {
Observable.timer(retryStrategy(count).toLong(), MILLISECONDS)
Observable.timer(retryStrategy(count).toLong(), MILLISECONDS, scheduler)
} else {
Observable.error(error as Throwable)
}