1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2026-06-27 05:35:13 +00:00

Compare commits

..

2 Commits

Author SHA1 Message Date
2d97d10ee1 fill changelog and readme 2025-09-25 14:25:22 +06:00
4b7d052ece rewrite firstOf 2025-09-25 14:25:08 +06:00
3 changed files with 22 additions and 2 deletions

View File

@@ -2,6 +2,14 @@
## 29.0.0
**THIS UPDATE CONTAINS ADDING SUPPORT OF [Telegram Bots API 9.2](https://core.telegram.org/bots/api-changelog#august-15-2025)**
**THIS UPDATE CONTAINS BREAKING CHANGES**
* `Core`:
* Add function `firstOfOrNull(vararg suspend () -> T): T?`
* Change logic of `firstOf` - now it works based on merged flows and __do not require__ `CoroutineScope` as receiver
## 28.0.3
* `Core`:

View File

@@ -1,4 +1,4 @@
# TelegramBotAPI [![Maven Central Version](https://img.shields.io/maven-central/v/dev.inmo/tgbotapi)](https://central.sonatype.com/artifact/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-9.1-blue)](https://core.telegram.org/bots/api-changelog#july-3-2025)
# TelegramBotAPI [![Maven Central Version](https://img.shields.io/maven-central/v/dev.inmo/tgbotapi)](https://central.sonatype.com/artifact/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-9.2-blue)](https://core.telegram.org/bots/api-changelog#august-15-2025)
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Mk&message=Docs&color=blue&logo=mkdocs)](https://docs.inmo.dev/tgbotapi/index.html) |
|:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|

View File

@@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.utils
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.merge
@@ -53,5 +54,16 @@ suspend fun <T> firstOfOrNull(
suspend fun <T> firstOf(
vararg deferreds: suspend () -> T
): T {
return firstOfOrNull(*deferreds) ?: error("Unable to get result of deferreds")
val resultFlow = deferreds.map {
flow {
runCatching {
it()
}.onSuccess {
emit(it)
}.onFailure {
if (it is CancellationException) throw it
}
}
}.merge()
return resultFlow.first()
}