When throttling E-Hentai, suspend the thread instead of sleeping it
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user