mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 12:08:43 +00:00
rewrite createAccumulatedUpdatesRetrieverFlow onto channelFlow
This commit is contained in:
parent
10f4817283
commit
098b5cc393
@ -14,6 +14,7 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update
|
|||||||
import dev.inmo.tgbotapi.updateshandlers.*
|
import dev.inmo.tgbotapi.updateshandlers.*
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import io.ktor.client.features.HttpRequestTimeoutException
|
import io.ktor.client.features.HttpRequestTimeoutException
|
||||||
|
import io.ktor.utils.io.core.use
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlin.coroutines.coroutineContext
|
import kotlin.coroutines.coroutineContext
|
||||||
@ -107,17 +108,19 @@ fun TelegramBot.createAccumulatedUpdatesRetrieverFlow(
|
|||||||
avoidCallbackQueries: Boolean = false,
|
avoidCallbackQueries: Boolean = false,
|
||||||
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
allowedUpdates: List<String>? = null
|
allowedUpdates: List<String>? = null
|
||||||
): Flow<Update> = flow {
|
): Flow<Update> = channelFlow {
|
||||||
val parentContext = kotlin.coroutines.coroutineContext
|
val parentContext = kotlin.coroutines.coroutineContext
|
||||||
|
channel.apply {
|
||||||
retrieveAccumulatedUpdates(
|
retrieveAccumulatedUpdates(
|
||||||
avoidInlineQueries,
|
avoidInlineQueries,
|
||||||
avoidCallbackQueries,
|
avoidCallbackQueries,
|
||||||
CoroutineScope(parentContext),
|
CoroutineScope(parentContext),
|
||||||
exceptionsHandler,
|
exceptionsHandler,
|
||||||
allowedUpdates
|
allowedUpdates,
|
||||||
) {
|
::send
|
||||||
withContext(parentContext) { emit(it) }
|
).join()
|
||||||
}.join()
|
close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TelegramBot.retrieveAccumulatedUpdates(
|
fun TelegramBot.retrieveAccumulatedUpdates(
|
||||||
|
Loading…
Reference in New Issue
Block a user