com.caesarealabs.rpc4k.runtime.api.RpcServerSetup.kt Maven / Gradle / Ivy
package com.caesarealabs.rpc4k.runtime.api
import com.caesarealabs.rpc4k.runtime.api.components.JsonFormat
import com.caesarealabs.rpc4k.runtime.api.components.KtorManagedRpcServer
import com.caesarealabs.rpc4k.runtime.implementation.handleImpl
class RpcServerSetup(
val handler: T,
val generatedHelper: GeneratedServerHelper,
val engine: Engine,
val format: SerializationFormat = JsonFormat()
) {
companion object {
// i want to get rid of this, not a very great api?
fun managedKtor(
handler: T, generatedHelper: GeneratedServerHelper, format: SerializationFormat = JsonFormat(),
ktorServer: KtorManagedRpcServer = KtorManagedRpcServer()
): RpcServerSetup {
return RpcServerSetup(handler, generatedHelper, ktorServer, format)
}
}
}
fun RpcServerSetup.withEngine(engine: NewEngine) =
RpcServerSetup(handler, generatedHelper, engine, format)
fun RpcServerSetup<*, Engine>.createServer(): RpcServerEngine.MultiCall.Instance = engine.create(this)
fun RpcServerSetup<*, Engine>.startServer(wait: Boolean)= engine.create(this)
.start(wait)
suspend fun > RpcServerSetup.handle(input: I, output: O) {
handleImpl(input, output)
}
suspend fun > RpcServerSetup.handle(input: I): O {
return handleImpl(input, null)!!
}