From facecf35fb0f54518252b547a28915e9d8b79f28 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 11 Aug 2025 00:45:35 +0600 Subject: [PATCH] add firstOf --- tgbotapi.core/api/tgbotapi.core.api | 4 ++++ .../ktor/base/DownloadFileRequestCallFactory.kt | 1 + .../kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt | 14 ++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt diff --git a/tgbotapi.core/api/tgbotapi.core.api b/tgbotapi.core/api/tgbotapi.core.api index 9c56d7a67c..3d576f9445 100644 --- a/tgbotapi.core/api/tgbotapi.core.api +++ b/tgbotapi.core/api/tgbotapi.core.api @@ -30671,6 +30671,10 @@ public final class dev/inmo/tgbotapi/utils/ExtractDataAndJsonFromDecoderKt { public static final fun decodeDataAndJson (Lkotlinx/serialization/encoding/Decoder;Lkotlinx/serialization/DeserializationStrategy;)Lkotlin/Pair; } +public final class dev/inmo/tgbotapi/utils/FirstOfKt { + public static final fun firstOf (Lkotlinx/coroutines/CoroutineScope;[Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +} + public final class dev/inmo/tgbotapi/utils/IntProgress100Serializer : kotlinx/serialization/KSerializer { public static final field INSTANCE Ldev/inmo/tgbotapi/utils/IntProgress100Serializer; public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object; diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DownloadFileRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DownloadFileRequestCallFactory.kt index 4fc2172b8f..1872e5eb54 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DownloadFileRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/base/DownloadFileRequestCallFactory.kt @@ -21,6 +21,7 @@ object DownloadFileRequestCallFactory : KtorCallFactory { jsonFormatter: Json, ): T? = (request as? DownloadFile)?.let { resolveFile(it.filePath) ?.let { + @Suppress("UNCHECKED_CAST") return@makeCall it.bytes() as T // Always ByteArray } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt new file mode 100644 index 0000000000..76c270cfe9 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt @@ -0,0 +1,14 @@ +package dev.inmo.tgbotapi.utils + +import dev.inmo.micro_utils.coroutines.firstOf +import kotlinx.coroutines.CoroutineScope + +suspend fun CoroutineScope.firstOf( + vararg deferreds: suspend () -> T +): T = firstOf { + deferreds.forEach { + add { + it() + } + } +}