All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xyz.cssxsh.bilibili.BiliApiMutex.kt Maven / Gradle / Ivy

The newest version!
package xyz.cssxsh.bilibili

import kotlinx.coroutines.*
import kotlinx.coroutines.sync.*

class BiliApiMutex(private val interval: Long) : Mutex by Mutex() {
    private val map = HashMap()

    suspend fun wait(type: String): Unit = withLock {
        val last = map[type] ?: 0
        while (System.currentTimeMillis() - last <= interval) {
            delay(1000L)
        }
        map[type] = System.currentTimeMillis()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy