Strict mode
Edit pageLast modified: 28 January 2025Starting with version 0.5.0
, the library introduces major changes to the service APIs. The following declarations will be gradually restricted:
StateFlow
andSharedFlow
Deprecation level:
WARNING
@Rpc interface Service : RemoteService { suspend fun old(): StateFlow<Int> // deprecated suspend fun new(): Flow<Int> // use .stateIn on the client side }
Fields
Deprecation level:
WARNING
@Rpc interface Service : RemoteService { val old: Flow<Int> // deprecated suspend fun new(): Flow<Int> // store flow locally }
Nested Flows
Deprecation level:
WARNING
@Rpc interface Service : RemoteService { suspend fun old(): Flow<Flow<Int>> // deprecated // no particular alternative, depends on the use case }
Not top-level server flows
Deprecation level:
WARNING
data class SpotifyWrapped(val myMusicFlow: Flow<Rap>, val extra: Data) @Rpc interface Service : RemoteService { suspend fun old(): SpotifyWrapped // deprecated // one should consider message delivery order when calling these suspend fun new(): Flow<Rap> suspend fun getData(): Data }
Deprecation levels are controlled by the Gradle rpc
extension:
// build.gradle.kts
plugins {
id("org.jetbrains.kotlinx.rpc.plugin")
}
rpc {
strict {
stateFlow = RpcStrictMode.WARNING
sharedFlow = RpcStrictMode.WARNING
nestedFlow = RpcStrictMode.WARNING
notTopLevelServerFlow = RpcStrictMode.WARNING
fields = RpcStrictMode.WARNING
}
}
Modes RpcStrictMode.NONE
and RpcStrictMode.ERROR
are available.
warning
Note that setting
RpcStrictMode.NONE
should not be done permanently. All deprecated APIs will become errors in future without an option to suppress it. Consider your migration path in advance.