Hi! I'm pretty knew to Kotlin coroutines and gRPC, my server code is generated with <grpc/grpc-kotli...
j

Johann Pardanaud

almost 4 years ago
Hi! I'm pretty knew to Kotlin coroutines and gRPC, my server code is generated with grpc/grpc-kotlin and I struggle a bit to understand how I can even use the first coroutine explained in Kotlin's documentation in my gRPC server. Say I have the following server method (from the Kotlin gRPC Quick start):
private class HelloWorldService : GreeterGrpcKt.GreeterCoroutineImplBase() {
    override suspend fun sayHello(request: HelloRequest) = helloReply {}
}
And I want to write the following code at the beginning of this method (from Kotlin's documentation):
launch {
    delay(1000L)
    println("World!")
}
println("Hello")
If I simply copy-paste this code in my method,
launch
isn't recognized as a valid method because it should by used on a coroutine scope. If I wrap my code with a
coroutineScope
like this:
override suspend fun sayHello(request: HelloRequest) = coroutineScope {
    launch {
        delay(1000L)
        println("World!")
    }
    println("Hello")

    helloReply {}
}
It builds, the code is even executed when I make a call from the client, however the server returns an
UNKNOWN
code before the
launch
job can even finish and the
HelloReply
is not used. So I think I shouldn't create my own coroutine scope and I should use a scope already defined by the server, but I don't find anything related to a "default gRPC coroutine scope" in the API reference. I must be missing something really obvious, can someone help me run this really basic code please? 🙏
I've upgraded my Compose Multiplatform (Android + iOS + Desktop) project from `Kotlin 2.1.0-Beta1` t...
a

Armond Avanes

about 1 year ago
I've upgraded my Compose Multiplatform (Android + iOS + Desktop) project from
Kotlin 2.1.0-Beta1
to
Kotlin-2.1.0-Beta2
and now I'm getting the following error when building the app to run on iOS Simulator:
Undefined symbols for architecture arm64:
  "_kfun:androidx.lifecycle.viewmodel.compose#access$<get-androidx_lifecycle_viewmodel_compose_LocalViewModelStoreOwner$stable>$p$tLocalViewModelStoreOwnerKt(){}kotlin.Int", referenced from:
      _kfun:com.test.RouteA#internal in composeApp[2](ComposeApp.framework.o)
      _kfun:com.test.RouteB#internal in composeApp[2](ComposeApp.framework.o)      _kfun:com.test#TestField(com.test.TestViewModel?;androidx.compose.ui.Modifier?;com.test.TestModel?;kotlin.String?;kotlin.Function0<kotlin.Unit>?;kotlin.Function0<kotlin.Unit>?;kotlin.Boolean;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){} in composeApp[2](ComposeApp.framework.o)
      _kfun:com.test.RouteC#internal in composeApp[2](ComposeApp.framework.o)
      _kfun:com.test.RouteD#internal in composeApp[2](ComposeApp.framework.o)
      ...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Android and Desktop builds are working fine. I'm using the following related multiplatform frameworks/libraries: • jetbrains compose: "1.7.0-rc01" • jetbrains lifecycle and viewmodel: "2.8.2" • jetbrains navigation compose: "2.8.0-alpha10" • koin: 4.0.0 I'll appreciate if someone can help.