When throttling E-Hentai, suspend the thread instead of sleeping it
This commit is contained in:
parent
fd65db51c1
commit
91ca176c28
@ -284,7 +284,7 @@ class EHentai(
|
||||
|
||||
override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> = getChapterList(manga) {}
|
||||
|
||||
suspend fun getChapterList(manga: MangaInfo, throttleFunc: () -> Unit): List<ChapterInfo> {
|
||||
suspend fun getChapterList(manga: MangaInfo, throttleFunc: suspend () -> Unit): List<ChapterInfo> {
|
||||
// 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() }
|
||||
})
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user