1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

rewrite createAccumulatedUpdatesRetrieverFlow onto channelFlow

This commit is contained in:
InsanusMokrassar 2021-02-09 16:33:48 +06:00
parent 10f4817283
commit 098b5cc393

View File

@ -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
retrieveAccumulatedUpdates( channel.apply {
avoidInlineQueries, retrieveAccumulatedUpdates(
avoidCallbackQueries, avoidInlineQueries,
CoroutineScope(parentContext), avoidCallbackQueries,
exceptionsHandler, CoroutineScope(parentContext),
allowedUpdates exceptionsHandler,
) { allowedUpdates,
withContext(parentContext) { emit(it) } ::send
}.join() ).join()
close()
}
} }
fun TelegramBot.retrieveAccumulatedUpdates( fun TelegramBot.retrieveAccumulatedUpdates(