1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-02 22:59:48 +00:00
This commit is contained in:
2020-05-14 13:11:46 +06:00
parent b5632626ad
commit b40cc0c1ea
7 changed files with 18 additions and 15 deletions

View File

@@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.supervisorScope
typealias ExceptionHandler<T> = suspend (Exception) -> T
/**
* It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions
*
@@ -10,7 +12,7 @@ import kotlinx.coroutines.supervisorScope
* exception will be available for catching
*/
suspend inline fun <T> handleSafely(
noinline onException: suspend (Exception) -> T = { throw it },
noinline onException: ExceptionHandler<T> = { throw it },
noinline block: suspend CoroutineScope.() -> T
): T {
return try {

View File

@@ -41,7 +41,7 @@ suspend fun RequestsExecutor.setWebhook(
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
allowedUpdates: List<String>? = null,
maxAllowedConnections: Int? = null,
exceptionsHandler: (suspend (Exception) -> Unit)? = null,
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
block: UpdateReceiver<Update>
): Job {
val executeDeferred = certificate ?.let {