Features
Edit pageLast modified: 04 April 2025Send 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
}
note
Note that flows that are declared in classes (like in
StreamResult
) require a Contextual annotation.