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