mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +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 {
|
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||||
return safely(
|
return runCatching {
|
||||||
|
safely(
|
||||||
{ e ->
|
{ e ->
|
||||||
pipelineStepsHolder.onRequestException(request, e) ?.let { return@safely it }
|
pipelineStepsHolder.onRequestException(request, e) ?.let { return@safely it }
|
||||||
|
|
||||||
@ -90,6 +91,7 @@ class KtorRequestsExecutor(
|
|||||||
} else {
|
} else {
|
||||||
e
|
e
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
|
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
|
||||||
@ -116,6 +118,9 @@ class KtorRequestsExecutor(
|
|||||||
} ?: pipelineStepsHolder.onRequestResultAbsent(request, callsFactories) ?: error("Can't execute request: $request")
|
} ?: pipelineStepsHolder.onRequestResultAbsent(request, callsFactories) ?: error("Can't execute request: $request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}.let {
|
||||||
|
pipelineStepsHolder.onRequestReturnResult(it, request, callsFactories)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
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
|
* 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
|
* 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?,
|
result: T?,
|
||||||
request: Request<T>,
|
request: Request<T>,
|
||||||
potentialFactory: KtorCallFactory
|
potentialFactory: KtorCallFactory
|
||||||
@ -45,7 +45,7 @@ interface KtorPipelineStepsHolder {
|
|||||||
* handled [request] and returned [result]. If returns value - that value will be returned from
|
* handled [request] and returned [result]. If returns value - that value will be returned from
|
||||||
* [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
|
* [dev.inmo.tgbotapi.bot.RequestsExecutor.execute] instead
|
||||||
*/
|
*/
|
||||||
suspend fun <T : Any> onRequestResultPresented(
|
suspend fun <T: Any> onRequestResultPresented(
|
||||||
result: T,
|
result: T,
|
||||||
request: Request<T>,
|
request: Request<T>,
|
||||||
resultCallFactory: KtorCallFactory,
|
resultCallFactory: KtorCallFactory,
|
||||||
@ -56,8 +56,18 @@ interface KtorPipelineStepsHolder {
|
|||||||
* Will be called when there is no [KtorCallFactory] from [callsFactories] which may handle [request]. If returns
|
* 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
|
* 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>,
|
request: Request<T>,
|
||||||
callsFactories: List<KtorCallFactory>
|
callsFactories: List<KtorCallFactory>
|
||||||
): T? = null
|
): 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