mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 14:20:24 +08:00
Fix packetListener removal
This commit is contained in:
parent
432a8690b1
commit
f0d8bbcc28
@ -329,7 +329,6 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
|
||||
val handler = PacketListener(commandName = commandName, sequenceId = sequenceId)
|
||||
packetListeners.addLast(handler)
|
||||
bot.logger.info("Send: ${this.commandName}")
|
||||
var lastException: Exception? = null
|
||||
repeat(retry + 1) {
|
||||
try {
|
||||
@ -338,17 +337,18 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
lastException = e
|
||||
}
|
||||
}
|
||||
packetListeners.remove(handler)
|
||||
throw lastException!!
|
||||
}
|
||||
|
||||
private suspend inline fun <E : Packet> OutgoingPacket.doSendAndReceive(timeoutMillis: Long = 3000, handler: PacketListener): E {
|
||||
channel.send(delegate)
|
||||
bot.logger.info("Send: ${this.commandName}")
|
||||
return withTimeoutOrNull(timeoutMillis) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
handler.await() as E
|
||||
// 不要 `withTimeout`. timeout 的异常会不知道去哪了.
|
||||
} ?: net.mamoe.mirai.qqandroid.utils.inline {
|
||||
packetListeners.remove(handler)
|
||||
error("timeout when receiving response of $commandName")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user