Commit 770865ca authored by Him188's avatar Him188

Make close not suspend

parent 785ddd73
......@@ -11,6 +11,7 @@ import net.mamoe.mirai.network.protocol.tim.packet.Packet
import net.mamoe.mirai.network.protocol.tim.packet.login.HeartbeatPacket
import net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult
import net.mamoe.mirai.network.protocol.tim.packet.login.RequestSKeyPacket
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.io.PlatformDatagramChannel
/**
......@@ -52,6 +53,7 @@ interface BotNetworkHandler<Socket : DataPacketSocketAdapter> : CoroutineScope {
* @see [BotSession.sendAndExpectAsync] 发送并期待一个包
* @see [TemporaryPacketHandler] 临时包处理器
*/
@MiraiInternalAPI
suspend fun addHandler(temporaryPacketHandler: TemporaryPacketHandler<*, *>)
/**
......@@ -67,7 +69,7 @@ interface BotNetworkHandler<Socket : DataPacketSocketAdapter> : CoroutineScope {
/**
* 关闭网络接口, 停止所有有关协程和任务
*/
suspend fun close(cause: Throwable? = null) {
fun close(cause: Throwable? = null) {
supervisor.cancel(CancellationException("handler closed", cause))
}
}
\ No newline at end of file
......@@ -101,16 +101,14 @@ internal class TIMBotNetworkHandler internal constructor(coroutineContext: Corou
heartbeatJob?.join()
}
override suspend fun close(cause: Throwable?) {
override fun close(cause: Throwable?) {
super.close(cause)
this.heartbeatJob?.cancel(CancellationException("handler closed"))
this.heartbeatJob?.join()//等待 cancel 完成
this.heartbeatJob = null
if (!this.loginResult.isCompleted && !this.loginResult.isCancelled) {
this.loginResult.cancel(CancellationException("socket closed"))
this.loginResult.join()
}
this.socket.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment