CoroutineNames

This commit is contained in:
Him188 2020-01-10 23:15:54 +08:00
parent d7b8d8b4d2
commit 66fb009627

View File

@ -113,7 +113,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
private var loginHandler: LoginHandler? = null private var loginHandler: LoginHandler? = null
private suspend fun processReceive() { private suspend inline fun processReceive() {
while (channel.isOpen) { while (channel.isOpen) {
val input: ByteReadPacket = try { val input: ByteReadPacket = try {
channel.read()// JVM: withContext(IO) channel.read()// JVM: withContext(IO)
@ -173,8 +173,8 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
expectingTouchResponse = Job(supervisor) expectingTouchResponse = Job(supervisor)
try { try {
launch { processReceive() } launch(CoroutineName("Packet Receiver")) { processReceive() }
launch { launch(CoroutineName("Timout checker")) {
if (withTimeoutOrNull(bot.configuration.touchTimeoutMillis) { expectingTouchResponse!!.join() } == null) { if (withTimeoutOrNull(bot.configuration.touchTimeoutMillis) { expectingTouchResponse!!.join() } == null) {
loginResult.complete(LoginResult.TIMEOUT) loginResult.complete(LoginResult.TIMEOUT)
} }
@ -189,7 +189,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
private var expectingTouchResponse: CompletableJob? = null private var expectingTouchResponse: CompletableJob? = null
private suspend fun <TPacket : Packet> handlePacket0( private suspend inline fun <TPacket : Packet> handlePacket0(
sequenceId: UShort, sequenceId: UShort,
packet: TPacket, packet: TPacket,
factory: PacketFactory<TPacket, *> factory: PacketFactory<TPacket, *>
@ -439,7 +439,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
BotLoginSucceedEvent(bot).broadcast() BotLoginSucceedEvent(bot).broadcast()
val configuration = bot.configuration val configuration = bot.configuration
heartbeatJob = this@TIMPCBotNetworkHandler.launch { heartbeatJob = this@TIMPCBotNetworkHandler.launch(CoroutineName("Heartbeat Job")) {
while (socket.isOpen) { while (socket.isOpen) {
delay(configuration.heartbeatPeriodMillis) delay(configuration.heartbeatPeriodMillis)
with(bot) { with(bot) {