Skip to content

Commit 60ff142

Browse files
committed
feat(isFlow): keep Flow<...> as returnType and add returnsFlow flag to RpcCallable
1 parent 6df0c11 commit 60ff142

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -797,23 +797,15 @@ internal class RpcStubGenerator(
797797
type = ctx.rpcCallable.typeWith(declaration.serviceType),
798798
symbol = ctx.rpcCallableDefault.constructors.single(),
799799
typeArgumentsCount = 1,
800-
valueArgumentsCount = 5,
800+
valueArgumentsCount = 6,
801801
constructorTypeArgumentsCount = 1,
802802
)
803803
}.apply {
804804
putConstructorTypeArgument(0, declaration.serviceType)
805805

806806
callable as ServiceDeclaration.Method
807807

808-
val returnType = when {
809-
callable.function.isNonSuspendingWithFlowReturn() -> {
810-
(callable.function.returnType as IrSimpleType).arguments.single().typeOrFail
811-
}
812-
813-
else -> {
814-
callable.function.returnType
815-
}
816-
}
808+
val returnType = callable.function.returnType
817809

818810
val invokator = invokators[callable.name]
819811
?: error("Expected invokator for ${callable.name} in ${declaration.service.name}")
@@ -889,6 +881,8 @@ internal class RpcStubGenerator(
889881
}
890882
}
891883

884+
val returnsFlowFlag = (callable.function.returnType.classOrNull == ctx.flow)
885+
892886
arguments {
893887
values {
894888
+stringConst(callable.name)
@@ -900,6 +894,7 @@ internal class RpcStubGenerator(
900894
+arrayOfCall
901895

902896
+booleanConst(!callable.function.isSuspend)
897+
+booleanConst(returnsFlowFlag)
903898
}
904899
}
905900
}

core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public interface RpcCallable<@Rpc T : Any> {
5656
public val invokator: RpcInvokator<T>
5757
public val parameters: Array<out RpcParameter>
5858
public val isNonSuspendFunction: Boolean
59+
/**
60+
* True if the method returns Flow<...> and should be treated as a streaming return.
61+
* The [returnType] remains the original declared KType (including Flow<...>),
62+
* consumers can use this flag to branch logic without relying on type unwrapping.
63+
*/
64+
public val returnsFlow: Boolean
5965
}
6066

6167
@ExperimentalRpcApi

core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptorDefault.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class RpcCallableDefault<@Rpc T : Any>(
1515
override val invokator: RpcInvokator<T>,
1616
override val parameters: Array<out RpcParameter>,
1717
override val isNonSuspendFunction: Boolean,
18+
override val returnsFlow: Boolean,
1819
) : RpcCallable<T>
1920

2021
@InternalRpcApi

0 commit comments

Comments
 (0)