rickclephas / KMP-NativeCoroutines

Library to use Kotlin Coroutines from Swift code in KMP apps
MIT License
1.07k stars 32 forks source link

Mutability Issue on suspend function issue with latest Ktor (2.0.0) + RxSwift wrapper #59

Closed bopbi closed 2 years ago

bopbi commented 2 years ago

When i try to grab a response string using Ktor 2.0.0 bodyAsText it show this error

the suspend function looks like this

class Greeting {
    private val client = HttpClient()
    suspend fun getHtml(): String {
        val response = client.get("https://ktor.io/docs")
        return response.bodyAsText()
    }
}

and the error

Domain=KotlinException Code=0 "Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread" UserInfo={KotlinException=kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread, NSLocalizedDescription=Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread}
rickclephas commented 2 years ago

Hi thanks for the report! Ktor 2.0 actually dropped support for the old memory model. Please try and use the -new-mm version with the new memory model.

bopbi commented 2 years ago

thanks for help, now i am able to run it after add the -new-mm on the library version and add kotlin.native.binary.memoryModel=experimental on the gradle.properties

i will close the issue