Add timeout for logout on close

This commit is contained in:
Him188 2022-05-21 15:21:01 +01:00
parent 6d0e5adf95
commit 753342d99e
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375

View File

@ -52,6 +52,7 @@ import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.lateinitMutableProperty
import kotlin.contracts.contract
import kotlin.time.Duration.Companion.seconds
internal fun Bot.asQQAndroidBot(): QQAndroidBot {
contract {
@ -73,7 +74,9 @@ internal open class QQAndroidBot constructor(
if (!this.isActive) return
runBlocking {
try { // this may not be very good but
components[SsoProcessor].logout(network)
withTimeoutOrNull(5.seconds) {
components[SsoProcessor].logout(network)
}
} catch (ignored: Exception) {
}
}