GRPC-Kotlin-Multiplatform icon indicating copy to clipboard operation
GRPC-Kotlin-Multiplatform copied to clipboard

KMStub with stream RPC calls are also marked as suspend ?

Open oianmol opened this issue 2 years ago • 2 comments

public expect class KMWorkspaceServiceStub private constructor() : KMStub<KMWorkspaceServiceStub> {
  public constructor(channel: KMChannel)

  public suspend fun getWorkspaces(request: KMEmpty, metadata: KMMetadata = KMMetadata()):
      Flow<KMSKWorkspaces>

  public suspend fun saveWorkspace(request: KMSKWorkspace, metadata: KMMetadata = KMMetadata()):
      KMSKWorkspace
}

Please check the generated code, the **getWorkspaces** method returns a Flow, so it should not be a suspend method.

oianmol avatar Sep 30 '22 17:09 oianmol

In JVMServiceWrite it should be

if (!rpc.isResponseStream) {
        beginControlFlow(
          "return %M",
          MemberName("io.github.timortel.kotlin_multiplatform_grpc_lib.rpc", "simpleCallImplementation")
        )
      } else {
        beginControlFlow(
          "return %M",
          MemberName("io.github.timortel.kotlin_multiplatform_grpc_lib.rpc", "simpleNonSuspendingCallImplementation")
        )
      }
fun <COMMON_RESPONSE> simpleNonSuspendingCallImplementation(
    performCall: () -> COMMON_RESPONSE
): COMMON_RESPONSE {
    return try {
        performCall()
    } catch (e: StatusException) {
        throw KMStatusException(KMStatus(KMCode.getCodeForValue(e.status.code.value()), e.status.description.orEmpty()), e)
    }
}


oianmol avatar Sep 30 '22 17:09 oianmol

Yes, the suspend is indeed not necessary. I will look into removing suspend from the server-side streaming functions. Thank you for the suggestion.

TimOrtel avatar Sep 30 '22 17:09 TimOrtel

This should be fixed in 0.3.0

TimOrtel avatar Mar 07 '23 20:03 TimOrtel