1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-09 09:53:47 +00:00

fixes in send action dsl

This commit is contained in:
InsanusMokrassar 2024-08-15 00:58:12 +06:00
parent a56ad7d671
commit c72f8e04ec

View File

@ -24,17 +24,17 @@ public suspend fun <T> TelegramBot.withAction(
contract { contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
} }
val actionScope = currentCoroutineContext().LinkedSupervisorScope(Job()) val actionScope = currentCoroutineContext().LinkedSupervisorScope()
actionScope.launch { actionScope.launch {
while (isActive) { while (isActive) {
safelyWithoutExceptions { runCatching {
execute(actionRequest) execute(actionRequest)
} }
delay(refreshTime) delay(refreshTime)
} }
} }
val result = runCatchingSafely { block() } val result = runCatchingSafely { block() }
actionScope.cancel() actionScope.coroutineContext.job.cancel()
return result.getOrThrow() return result.getOrThrow()
} }