diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt index 7d19100ddc..dd1698d6b8 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPoller.kt @@ -11,16 +11,13 @@ import com.github.insanusmokrassar.TelegramBotAPI.utils.toMediaGroupUpdate import kotlinx.coroutines.* import java.util.concurrent.Executors -private val updatesPollerRequestExecutorCollectedException = IllegalStateException("RequestsExecutor was collected by GC. Can't continue getting updates by polling") - class UpdatesPoller( - requestsExecutor: RequestsExecutor, + private val executor: RequestsExecutor, private val requestsDelayMillis: Long = 1000, private val scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), private val allowedUpdates: List? = null, private val block: UpdateReceiver ) { - private val executor = requestsExecutor.asReference() private var lastHandledUpdate: UpdateIdentifier = 0L private val mediaGroup: MutableList = mutableListOf() @@ -51,14 +48,14 @@ class UpdatesPoller( } private suspend fun getUpdates(): List { - return executor.get() ?.execute( + return executor.execute( GetUpdates( lastHandledUpdate + 1, // incremented because offset counted from 1 when updates id from 0 allowed_updates = allowedUpdates ) ) ?.map { it.asUpdate - } ?: throw updatesPollerRequestExecutorCollectedException + } } private suspend fun handleUpdates(updates: List) { @@ -82,9 +79,6 @@ class UpdatesPoller( try { handleUpdates(getUpdates()) } catch (e: Exception) { - if (e == updatesPollerRequestExecutorCollectedException) { - throw IllegalArgumentException(e.message) - } e.printStackTrace() } }