Skip to content

Commit c705f35

Browse files
committed
Fix KRPC-173 (#315)
1 parent 34638f4 commit c705f35

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
@@ -108,6 +108,8 @@ interface KrpcTestService : RemoteService {
108108

109109
suspend fun answerToAnything(arg: String): Int
110110

111+
suspend fun krpc173()
112+
111113
val plainFlowOfInts : Flow<Int>
112114

113115
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
@@ -265,6 +265,15 @@ class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) :
265265
return 42
266266
}
267267

268+
private suspend fun doWork(): String {
269+
delay(1)
270+
return "qwerty"
271+
}
272+
273+
override suspend fun krpc173() {
274+
doWork()
275+
}
276+
268277
override val plainFlowOfInts: Flow<Int> = plainFlow { it }
269278

270279
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
@@ -548,6 +548,11 @@ abstract class KrpcTransportTestBase {
548548
awaitAll(c1, c2)
549549
}
550550

551+
@Test
552+
fun testKrpc173() = runTest {
553+
assertEquals(Unit, client.krpc173())
554+
}
555+
551556
@Test
552557
fun testPlainFlowOfInts() = runTest {
553558
val flow = client.plainFlowOfInts.toList()

0 commit comments

Comments
 (0)