mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
add KtorPipelineStepsHolder#onRequestReturnResult
This commit is contained in:
parent
863c872f35
commit
81ad55b19f
@ -75,7 +75,8 @@ class KtorRequestsExecutor(
|
||||
}
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
return safely(
|
||||
return runCatching {
|
||||
safely(
|
||||
{ e ->
|
||||
pipelineStepsHolder.onRequestException(request, e) ?.let { return@safely it }
|
||||
|
||||
@ -90,6 +91,7 @@ class KtorRequestsExecutor(
|
||||
} else {
|
||||
e
|
||||
}
|
||||
|
||||
}
|
||||
) {
|
||||
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
|
||||
@ -116,6 +118,9 @@ class KtorRequestsExecutor(
|
||||
} ?: pipelineStepsHolder.onRequestResultAbsent(request, callsFactories) ?: error("Can't execute request: $request")
|
||||
}
|
||||
}
|
||||
}.let {
|
||||
pipelineStepsHolder.onRequestReturnResult(it, request, callsFactories)
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
|
@ -34,7 +34,7 @@ interface KtorPipelineStepsHolder {
|
||||
* Will always be called after [potentialFactory] has tried to make [request] and got some [result]. If returns
|
||||
* value - that value will be returned from [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
|
||||
*/
|
||||
suspend fun <T : Any> onAfterCallFactoryMakeCall(
|
||||
suspend fun <T: Any> onAfterCallFactoryMakeCall(
|
||||
result: T?,
|
||||
request: Request<T>,
|
||||
potentialFactory: KtorCallFactory
|
||||
@ -45,7 +45,7 @@ interface KtorPipelineStepsHolder {
|
||||
* handled [request] and returned [result]. If returns value - that value will be returned from
|
||||
* [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
|
||||
*/
|
||||
suspend fun <T : Any> onRequestResultPresented(
|
||||
suspend fun <T: Any> onRequestResultPresented(
|
||||
result: T,
|
||||
request: Request<T>,
|
||||
resultCallFactory: KtorCallFactory,
|
||||
@ -56,8 +56,18 @@ interface KtorPipelineStepsHolder {
|
||||
* Will be called when there is no [KtorCallFactory] from [callsFactories] which may handle [request]. If returns
|
||||
* value - that value will be returned from [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
|
||||
*/
|
||||
suspend fun <T : Any> onRequestResultAbsent(
|
||||
suspend fun <T: Any> onRequestResultAbsent(
|
||||
request: Request<T>,
|
||||
callsFactories: List<KtorCallFactory>
|
||||
): T? = null
|
||||
|
||||
/**
|
||||
* This step will be called when the [result] has been retrieved (or exception has happened). If returns value -
|
||||
* that value will be returned from [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
|
||||
*/
|
||||
suspend fun <T: Any> onRequestReturnResult(
|
||||
result: Result<T>,
|
||||
request: Request<T>,
|
||||
callsFactories: List<KtorCallFactory>
|
||||
): T = result.getOrThrow()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user