mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 03:28:44 +00:00
make small improvement in send action dsl
This commit is contained in:
parent
77158ffecf
commit
a56ad7d671
@ -1,5 +1,7 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.send
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.LinkedSupervisorScope
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
||||
import dev.inmo.micro_utils.coroutines.safelyWithResult
|
||||
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
@ -22,7 +24,8 @@ public suspend fun <T> TelegramBot.withAction(
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
val botActionJob = CoroutineScope(currentCoroutineContext()).launch {
|
||||
val actionScope = currentCoroutineContext().LinkedSupervisorScope(Job())
|
||||
actionScope.launch {
|
||||
while (isActive) {
|
||||
safelyWithoutExceptions {
|
||||
execute(actionRequest)
|
||||
@ -30,8 +33,8 @@ public suspend fun <T> TelegramBot.withAction(
|
||||
delay(refreshTime)
|
||||
}
|
||||
}
|
||||
val result = safelyWithResult { block() }
|
||||
botActionJob.cancel()
|
||||
val result = runCatchingSafely { block() }
|
||||
actionScope.cancel()
|
||||
return result.getOrThrow()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user