RpcHostService

A service whose methods may return other @KsService sub-services.

Extend this instead of RpcService when any @KsMethod returns a type annotated with @KsService. The compiler plugin enforces this at compile time and produces a clear error if the wrong tier is used.

HTTP transports can host RpcHostService instances (sub-service outputs are multiplexed over the same connection), but cannot host RpcBidiService.

Samples

import com.monkopedia.ksrpc.RpcBidiService
import com.monkopedia.ksrpc.RpcHostService
import com.monkopedia.ksrpc.RpcService
import com.monkopedia.ksrpc.annotation.KsMethod
import com.monkopedia.ksrpc.annotation.KsService
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.rpcObject
import com.monkopedia.ksrpc.serialized
import com.monkopedia.ksrpc.toStub

fun main() { 
   //sampleStart 
   // A @KsMethod can return another @KsService type. The returned service
// is hosted as a sub-service on the same connection, with its own
// channel id managed by the framework.
val factory = object : WorkerFactory {
    override suspend fun createWorker(name: String): ScopedWorker = object : ScopedWorker {
        override suspend fun execute(command: String): String = "[$name] executed: $command"
    }
}

// Serialize and use through a stub -- sub-services work transparently.
val env = ksrpcEnvironment { }
val serialized = factory.serialized(env)
val stub = serialized.toStub<WorkerFactory, String>()
val worker = stub.createWorker("build")
val result = worker.execute("compile") 
   //sampleEnd
}

Inheritors

Functions

Link copied to clipboard
open suspend override fun close()

Called when the interaction with this object is done and its resources can be cleaned up.