diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt index f8250d07f..a895799d8 100755 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/all/EHentai.kt @@ -284,7 +284,7 @@ class EHentai( override suspend fun getChapterList(manga: MangaInfo): List = getChapterList(manga) {} - suspend fun getChapterList(manga: MangaInfo, throttleFunc: () -> Unit): List { + suspend fun getChapterList(manga: MangaInfo, throttleFunc: suspend () -> Unit): List { // Pull all the way to the root gallery // We can't do this with RxJava or we run into stack overflows on shit like this: // https://exhentai.org/g/1073061/f9345f1c12/ @@ -357,7 +357,7 @@ class EHentai( @Suppress("DeprecatedCallableAddReplaceWith") @Deprecated("Use getChapterList instead") - fun fetchChapterList(manga: SManga, throttleFunc: () -> Unit) = runAsObservable({ + fun fetchChapterList(manga: SManga, throttleFunc: suspend () -> Unit) = runAsObservable({ getChapterList(manga.toMangaInfo(), throttleFunc).map { it.toSChapter() } }) diff --git a/app/src/main/java/exh/GalleryAdder.kt b/app/src/main/java/exh/GalleryAdder.kt index b5ce947ea..c71544736 100755 --- a/app/src/main/java/exh/GalleryAdder.kt +++ b/app/src/main/java/exh/GalleryAdder.kt @@ -53,7 +53,7 @@ class GalleryAdder { url: String, fav: Boolean = false, forceSource: UrlImportableSource? = null, - throttleFunc: () -> Unit = {} + throttleFunc: suspend () -> Unit = {} ): GalleryAddEvent { logger.d(context.getString(R.string.gallery_adder_importing_manga, url, fav.toString(), forceSource)) try { diff --git a/app/src/main/java/exh/eh/EHentaiThrottleManager.kt b/app/src/main/java/exh/eh/EHentaiThrottleManager.kt index 278fa62eb..2661cf614 100644 --- a/app/src/main/java/exh/eh/EHentaiThrottleManager.kt +++ b/app/src/main/java/exh/eh/EHentaiThrottleManager.kt @@ -1,5 +1,7 @@ package exh.eh +import kotlinx.coroutines.delay + class EHentaiThrottleManager( private val max: Int = THROTTLE_MAX, private val inc: Int = THROTTLE_INC @@ -8,12 +10,12 @@ class EHentaiThrottleManager( var throttleTime: Long = 0 private set - fun throttle() { + suspend fun throttle() { // Throttle requests if necessary val now = System.currentTimeMillis() val timeDiff = now - lastThrottleTime if (timeDiff < throttleTime) { - Thread.sleep(throttleTime - timeDiff) + delay(throttleTime - timeDiff) } if (throttleTime < max) {