From bcf2325be8e7683fbd21bc9b89c33a0fcfe0ad39 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 8 Apr 2020 13:19:19 +0600 Subject: [PATCH] make new startGettingOfUpdates more useful --- .../extensions/api/updates/UpdatesPolling.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt index bdc3e64455..d186de7222 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt @@ -65,17 +65,20 @@ fun RequestsExecutor.startGettingOfUpdates( } /** - * This method will create a new one [FlowsUpdatesFilter]. This method is unsafe due to the fact that it will start + * This method will create a new one [FlowsUpdatesFilter]. This method could be unsafe due to the fact that it will start * getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call - * [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows + * [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows. To avoid it, you can pass + * [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting */ @PreviewFeature fun RequestsExecutor.startGettingOfUpdates( timeoutSeconds: Seconds = 30, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), exceptionsHandler: (suspend (Exception) -> Unit)? = null, - flowsUpdatesFilterUpdatesKeeperCount: Int = 64 + flowsUpdatesFilterUpdatesKeeperCount: Int = 64, + flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {} ): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply { + flowUpdatesPreset() startGettingOfUpdates(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver) }