我正在遵循此帮助页面上的说明:https ://ktor.io/advanced/pipeline/route.html
他们举了这个例子:
fun Route.routeTimeout(time: Long, unit: TimeUnit = TimeUnit.SECONDS, callback: Route.() -> Unit): Route {
// With createChild, we create a child node for this received Route
val routeWithTimeout = this.createChild(object : RouteSelector(1.0) {
override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation =
RouteSelectorEvaluation.Constant
})
// Intercepts calls from this route at the features step
routeWithTimeout.intercept(ApplicationCallPipeline.Features) {
withTimeout(time, unit) {
proceed() // With proceed we can define code to be executed before and after the call
}
}
// Configure this route with the block provided by the user
callback(routeWithTimeout)
return routeWithTimeout
}
我想修改它以便可以保持状态。例如,每个下一个调用者都会获得更大的超时。我把我的状态放在哪里?