From b03e02675bec2c1631d0f47826f4e92fdd838b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E6=B1=A0?= <98259561+whitechi73@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:16:12 +0800 Subject: [PATCH] `Shamrock`: add `timeout` #223 --- .../shamrock/remote/action/handlers/GetGProChannelList.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetGProChannelList.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetGProChannelList.kt index 25d2cd15..5825a65c 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetGProChannelList.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/GetGProChannelList.kt @@ -1,5 +1,6 @@ package moe.fuqiuluo.shamrock.remote.action.handlers +import kotlinx.coroutines.withTimeoutOrNull import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonElement @@ -18,8 +19,10 @@ internal object GetGProChannelList: IActionHandler() { return invoke(guildId.toULong(), refresh, echo = session.echo) } - operator fun invoke(guildId: ULong, refresh: Boolean, echo: JsonElement = EmptyJsonString): String { - val result = GProSvc.getChannelList(guildId, refresh) + suspend operator fun invoke(guildId: ULong, refresh: Boolean, echo: JsonElement = EmptyJsonString): String { + val result = withTimeoutOrNull(5000) { + GProSvc.getChannelList(guildId, refresh) + } ?: return error("timeout", echo) result.onFailure { return error(it.message ?: "unable to fetch channel list", echo) }