Add throttling when restoring E-Hentai/ExHentai galleries.

This commit is contained in:
NerdNumber9
2019-04-19 22:59:24 -04:00
parent 6ada3cbf59
commit 39e0d434ad
6 changed files with 76 additions and 37 deletions

View File

@@ -0,0 +1,31 @@
package exh.eh
class EHentaiThrottleManager(private val max: Int = THROTTLE_MAX,
private val inc: Int = THROTTLE_INC) {
private var lastThrottleTime: Long = 0
var throttleTime: Long = 0
private set
fun throttle() {
//Throttle requests if necessary
val now = System.currentTimeMillis()
val timeDiff = now - lastThrottleTime
if(timeDiff < throttleTime)
Thread.sleep(throttleTime - timeDiff)
if(throttleTime < max)
throttleTime += inc
lastThrottleTime = System.currentTimeMillis()
}
fun resetThrottle() {
lastThrottleTime = 0
throttleTime = 0
}
companion object {
const val THROTTLE_MAX = 5500
const val THROTTLE_INC = 20
}
}