mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
now startGettingOfUpdates have exceptions handler as argument
This commit is contained in:
parent
c9de4bc79e
commit
518dee46b3
@ -17,6 +17,7 @@ import kotlinx.coroutines.*
|
|||||||
fun RequestsExecutor.startGettingOfUpdates(
|
fun RequestsExecutor.startGettingOfUpdates(
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
allowedUpdates: List<String>? = null,
|
allowedUpdates: List<String>? = null,
|
||||||
updatesReceiver: UpdateReceiver<Update>
|
updatesReceiver: UpdateReceiver<Update>
|
||||||
): Job = scope.launch {
|
): Job = scope.launch {
|
||||||
@ -40,10 +41,12 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: HttpRequestTimeoutException) {
|
} catch (e: HttpRequestTimeoutException) {
|
||||||
e // it is ok due to mechanism of long polling
|
exceptionsHandler ?.invoke(e) // it is ok due to mechanism of long polling
|
||||||
} catch (e: RequestException) {
|
} catch (e: RequestException) {
|
||||||
e // it is not ok, but in most cases it will mean that there is some limit for requests count
|
exceptionsHandler ?.invoke(e) // it is not ok, but in most cases it will mean that there is some limit for requests count
|
||||||
delay(1000L)
|
delay(1000L)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
exceptionsHandler ?.invoke(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,10 +54,12 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
fun RequestsExecutor.startGettingOfUpdates(
|
fun RequestsExecutor.startGettingOfUpdates(
|
||||||
updatesFilter: UpdatesFilter,
|
updatesFilter: UpdatesFilter,
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
): Job = startGettingOfUpdates(
|
): Job = startGettingOfUpdates(
|
||||||
timeoutSeconds,
|
timeoutSeconds,
|
||||||
scope,
|
scope,
|
||||||
|
exceptionsHandler,
|
||||||
updatesFilter.allowedUpdates,
|
updatesFilter.allowedUpdates,
|
||||||
updatesFilter.asUpdateReceiver
|
updatesFilter.asUpdateReceiver
|
||||||
)
|
)
|
||||||
@ -76,6 +81,7 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
scope: CoroutineScope = GlobalScope
|
scope: CoroutineScope = GlobalScope
|
||||||
): Job {
|
): Job {
|
||||||
return startGettingOfUpdates(
|
return startGettingOfUpdates(
|
||||||
@ -97,6 +103,7 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollAnswerCallback
|
pollAnswerCallback
|
||||||
),
|
),
|
||||||
timeoutSeconds,
|
timeoutSeconds,
|
||||||
|
exceptionsHandler,
|
||||||
scope
|
scope
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -115,6 +122,7 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
pollCallback: UpdateReceiver<PollUpdate>? = null,
|
||||||
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
pollAnswerCallback: UpdateReceiver<PollAnswerUpdate>? = null,
|
||||||
timeoutSeconds: Seconds = 30,
|
timeoutSeconds: Seconds = 30,
|
||||||
|
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
): Job = startGettingOfUpdates(
|
): Job = startGettingOfUpdates(
|
||||||
messageCallback = messageCallback,
|
messageCallback = messageCallback,
|
||||||
@ -133,5 +141,6 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
pollCallback = pollCallback,
|
pollCallback = pollCallback,
|
||||||
pollAnswerCallback = pollAnswerCallback,
|
pollAnswerCallback = pollAnswerCallback,
|
||||||
timeoutSeconds = timeoutSeconds,
|
timeoutSeconds = timeoutSeconds,
|
||||||
|
exceptionsHandler = exceptionsHandler,
|
||||||
scope = scope
|
scope = scope
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user