mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
updates after coroutines version change
This commit is contained in:
parent
d8dbbdf549
commit
6d782f28c3
@ -5,6 +5,9 @@
|
|||||||
* `Common`:
|
* `Common`:
|
||||||
* Version updates:
|
* Version updates:
|
||||||
* `Coroutines`: `1.3.9` -> `1.4.0`
|
* `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
|
## 0.29.1
|
||||||
|
|
||||||
|
@ -5,21 +5,20 @@ import dev.inmo.tgbotapi.types.update.*
|
|||||||
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
|
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
|
|
||||||
@Suppress("EXPERIMENTAL_API_USAGE", "unused")
|
@Suppress("EXPERIMENTAL_API_USAGE", "unused")
|
||||||
class FlowsUpdatesFilter(
|
class FlowsUpdatesFilter(
|
||||||
broadcastChannelsSize: Int = 100
|
broadcastChannelsSize: Int = 100
|
||||||
): UpdatesFilter {
|
): UpdatesFilter {
|
||||||
private val updatesReceivingChannel = BroadcastChannel<Update>(broadcastChannelsSize)
|
private val updatesSharedFlow = MutableSharedFlow<Update>(extraBufferCapacity = broadcastChannelsSize)
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
val allUpdatesFlow: Flow<Update> = updatesReceivingChannel.asFlow()
|
val allUpdatesFlow: Flow<Update> = updatesSharedFlow.asSharedFlow()
|
||||||
|
|
||||||
override val allowedUpdates: List<String>
|
override val allowedUpdates: List<String>
|
||||||
get() = ALL_UPDATES_LIST
|
get() = ALL_UPDATES_LIST
|
||||||
override val asUpdateReceiver: UpdateReceiver<Update> = {
|
override val asUpdateReceiver: UpdateReceiver<Update> = {
|
||||||
updatesReceivingChannel.send(it)
|
updatesSharedFlow.emit(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
val messageFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
|
val messageFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
|
@ -11,6 +11,7 @@ private sealed class DebounceAction<T> {
|
|||||||
private data class AddValue<T>(override val value: T) : DebounceAction<T>()
|
private data class AddValue<T>(override val value: T) : DebounceAction<T>()
|
||||||
private data class RemoveJob<T>(override val value: T, val job: Job) : DebounceAction<T>()
|
private data class RemoveJob<T>(override val value: T, val job: Job) : DebounceAction<T>()
|
||||||
|
|
||||||
|
@Deprecated("Unused and will be removed in next major release")
|
||||||
fun <T> ReceiveChannel<T>.debounceByValue(
|
fun <T> ReceiveChannel<T>.debounceByValue(
|
||||||
delayMillis: Long,
|
delayMillis: Long,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||||
|
@ -13,10 +13,11 @@ fun <T> aggregateFlows(
|
|||||||
vararg flows: Flow<T>,
|
vararg flows: Flow<T>,
|
||||||
internalBufferSize: Int = Channel.BUFFERED
|
internalBufferSize: Int = Channel.BUFFERED
|
||||||
): Flow<T> {
|
): Flow<T> {
|
||||||
|
val sharedFlow = MutableSharedFlow<T>(extraBufferCapacity = internalBufferSize)
|
||||||
val bc = BroadcastChannel<T>(internalBufferSize)
|
val bc = BroadcastChannel<T>(internalBufferSize)
|
||||||
flows.forEach {
|
flows.forEach {
|
||||||
it.onEach {
|
it.onEach {
|
||||||
safely { bc.send(it) }
|
safely { sharedFlow.emit(it) }
|
||||||
}.launchIn(withScope)
|
}.launchIn(withScope)
|
||||||
}
|
}
|
||||||
return bc.asFlow()
|
return bc.asFlow()
|
||||||
|
Loading…
Reference in New Issue
Block a user