Skip to content

Commit 7e8bc38

Browse files
authored
Fix KRPC-173 (#315) (#317)
1 parent b01ceb3 commit 7e8bc38

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import kotlinx.serialization.KSerializer
2121
import kotlinx.serialization.SerialFormat
2222
import kotlinx.serialization.StringFormat
2323
import kotlin.coroutines.CoroutineContext
24+
import kotlin.reflect.typeOf
2425

2526
internal class KrpcServerService<@Rpc T : Any>(
2627
private val service: T,
@@ -178,6 +179,13 @@ internal class KrpcServerService<@Rpc T : Any>(
178179
is RpcInvokator.Field -> {
179180
invokator.call(service)
180181
}
182+
}.let { interceptedValue ->
183+
// KRPC-173
184+
if (callable.returnType.kType == typeOf<Unit>()) {
185+
Unit
186+
} else {
187+
interceptedValue
188+
}
181189
}
182190

183191
val returnType = callable.returnType

krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ interface KrpcTestService : RemoteService {
111111

112112
suspend fun answerToAnything(arg: String): Int
113113

114+
suspend fun krpc173()
115+
114116
val plainFlowOfInts : Flow<Int>
115117

116118
val plainFlowOfFlowsOfInts : Flow<Flow<Int>>

krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
273273
return 42
274274
}
275275

276+
private suspend fun doWork(): String {
277+
delay(1)
278+
return "qwerty"
279+
}
280+
281+
override suspend fun krpc173() {
282+
doWork()
283+
}
284+
276285
override val plainFlowOfInts: Flow<Int> = plainFlow { it }
277286

278287
override val plainFlowOfFlowsOfInts: Flow<Flow<Int>> = plainFlow { plainFlow { i -> i } }

krpc/krpc-test/src/commonMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ abstract class KrpcTransportTestBase {
564564
awaitAll(c1, c2)
565565
}
566566

567+
@Test
568+
fun testKrpc173() = runTest {
569+
assertEquals(Unit, client.krpc173())
570+
}
571+
567572
@Test
568573
fun testPlainFlowOfInts() = runTest {
569574
val flow = client.plainFlowOfInts.toList()

0 commit comments

Comments
 (0)