commonMain.ch.softappeal.yass2.Interceptor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yass2-jvm Show documentation
Show all versions of yass2-jvm Show documentation
Yet Another Service Solution
package ch.softappeal.yass2
import kotlin.reflect.*
typealias Invocation = suspend () -> Any?
typealias Interceptor = suspend (functionName: String, parameters: Array, invocation: Invocation) -> Any?
interface ProxyFactory {
fun create(service: KClass, implementation: S, interceptor: Interceptor): S
}
val EmptyInterceptor: Interceptor = { _, _, invocation -> invocation() }
inline operator fun ProxyFactory.invoke(implementation: S, noinline interceptor: Interceptor): S =
if (interceptor === EmptyInterceptor) implementation else create(S::class, implementation, interceptor)
operator fun Interceptor.plus(second: Interceptor): Interceptor = when {
this === EmptyInterceptor -> second
second === EmptyInterceptor -> this
else -> { functionName, parameters, invocation ->
this(functionName, parameters) { second(functionName, parameters, invocation) }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy