diff --git a/CHANGELOG.md b/CHANGELOG.md index d3ee49eeb6..0c3b61ffa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # TelegramBotAPI changelog +## 0.29.2 + +* `Common`: + * Version updates: + * `Coroutines`: `1.3.9` -> `1.4.0` + * Internal broadcast channels were replaced with `SharedFlow` +* `TelegramBotAPI-extensions-utils`: + * Extension `ReceiveChannel#debounceByValue` has been deprecated + ## 0.29.1 * `Common`: diff --git a/gradle.properties b/gradle.properties index 58ea578fb8..fab9a91783 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.incremental=true kotlin.incremental.js=true kotlin_version=1.4.10 -kotlin_coroutines_version=1.3.9 +kotlin_coroutines_version=1.4.0 kotlin_serialisation_runtime_version=1.0.0 klock_version=1.12.1 uuid_version=0.2.2 @@ -15,7 +15,7 @@ ktor_version=1.4.1 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.29.1 +library_version=0.29.2 gradle_bintray_plugin_version=1.8.5 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt index 616fa4bfce..1e8adcf5f0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt @@ -5,21 +5,20 @@ import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update -import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.flow.* @Suppress("EXPERIMENTAL_API_USAGE", "unused") class FlowsUpdatesFilter( broadcastChannelsSize: Int = 100 ): UpdatesFilter { - private val updatesReceivingChannel = BroadcastChannel(broadcastChannelsSize) + private val updatesSharedFlow = MutableSharedFlow(extraBufferCapacity = broadcastChannelsSize) @Suppress("MemberVisibilityCanBePrivate") - val allUpdatesFlow: Flow = updatesReceivingChannel.asFlow() + val allUpdatesFlow: Flow = updatesSharedFlow.asSharedFlow() override val allowedUpdates: List get() = ALL_UPDATES_LIST override val asUpdateReceiver: UpdateReceiver = { - updatesReceivingChannel.send(it) + updatesSharedFlow.emit(it) } val messageFlow: Flow = allUpdatesFlow.filterIsInstance() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt index fe239ed191..4094709bce 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/extensions/ReceiveChannel.kt @@ -11,6 +11,7 @@ private sealed class DebounceAction { private data class AddValue(override val value: T) : DebounceAction() private data class RemoveJob(override val value: T, val job: Job) : DebounceAction() +@Deprecated("Unused and will be removed in next major release") fun ReceiveChannel.debounceByValue( delayMillis: Long, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/FlowsAggregation.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/FlowsAggregation.kt index 3eb1b9f88b..bf4c4b8f74 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/FlowsAggregation.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/FlowsAggregation.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.extensions.utils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BroadcastChannel -import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.* /** @@ -11,15 +10,15 @@ import kotlinx.coroutines.flow.* fun aggregateFlows( withScope: CoroutineScope, vararg flows: Flow, - internalBufferSize: Int = Channel.BUFFERED + internalBufferSize: Int = 64 ): Flow { - val bc = BroadcastChannel(internalBufferSize) + val sharedFlow = MutableSharedFlow(extraBufferCapacity = internalBufferSize) flows.forEach { it.onEach { - safely { bc.send(it) } + safely { sharedFlow.emit(it) } }.launchIn(withScope) } - return bc.asFlow() + return sharedFlow } fun Flow>.flatMap(): Flow = flow {