kotlinx.rpc 0.6.2 Help

Features

Send and receive Flows

You can send and receive Kotlin Flows in RPC methods. However, this only applies to the Flow type. StateFlow and SharedFlow are not supported, and there are no plans to add support for them.

@Serializable data class StreamRequest( @Contextual val innerFlow: Flow<Int> ) @Rpc interface MyService : RemoteService { fun sendStream(stream: Flow<Int>): Flow<String> suspend fun streamRequest(request: StreamRequest) }

Another requirement is that server-side steaming (flows that are returned from a function), must be the top-level type and the function must be non-suspending:

@Serializable data class StreamResult( @Contextual val innerFlow: Flow<Int> ) @Rpc interface MyService : RemoteService { fun serverStream(): Flow<String> // ok suspend fun serverStream(): Flow<String> // not ok suspend fun serverStream(): StreamResult // not ok }
Last modified: 04 April 2025