From 4dd9740fec5131886345450a9c5f07e6aa89bab4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 11 Aug 2025 15:50:06 +0600 Subject: [PATCH] fill changelog and add kdocs for firstOf --- CHANGELOG.md | 7 +++++++ .../kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f129c7c816..a5c9be0771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## 28.0.0 +* `Core`: + * Add `firstOf` extension +* `BehaviourBuilder`: + * All builders for behaviours got boolean `useDefaultSubcontextInitialAction` + * Add opportunity to pass `BehaviourContextData` in `DefaultBehaviourContext` constructor and `copy` method + * By default, commands to other bots will be ignored in triggers and waiters + ## 27.1.2 * `Core`: 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 index 76c270cfe9..4863c34e7a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/FirstOf.kt @@ -3,6 +3,18 @@ package dev.inmo.tgbotapi.utils import dev.inmo.micro_utils.coroutines.firstOf import kotlinx.coroutines.CoroutineScope +/** + * Launches all provided suspending [deferreds] in this [CoroutineScope] and returns the value + * produced by the first block that completes. + * + * - Provide at least one block; otherwise the call will never complete. + * - Cancellation and error propagation semantics are delegated to the underlying + * dev.inmo.micro_utils.coroutines.firstOf implementation. + * + * @param T The type of the resulting value. + * @param deferreds The suspending blocks to race; they are started eagerly. + * @return The result produced by the first completed block. + */ suspend fun CoroutineScope.firstOf( vararg deferreds: suspend () -> T ): T = firstOf {