https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

sikri

01/20/2020, 10:06 PM
If I create an object in swift, that is defined in kotlin/common or kotlin/ios module, is it considered frozen by defauly?
k

Kris Wong

01/20/2020, 10:15 PM
no
s

sikri

01/20/2020, 10:31 PM
I have client api class in common module
Copy code
class ClientApi(
    private val versionName: String
) {

    private val client = HttpClient()
    suspend fun getFrom(path: String) = client
        .get<String>(urlString = path)
}
I have an extension method in ios module:
Copy code
fun ClientApi.getFrom(path: String, block: (Result) -> Unit) {
GlobalScope.launch(Dispatchers.Default) {
        val result = getFrom(path)
        launch(MainLoopDispatcher) {
            block(screen)
        }
    }
}
I initialize client in swift and use an extension method. I’ve received an exception
Copy code
Caused by: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen io.ktor.client.request.HttpRequestPipeline@17e66c8
Can it be a result of using coroutines of 1.3.3-mt-native branch?
k

Kris Wong

01/20/2020, 10:57 PM
yes, you're passing
client
across thread boundaries, which feezes it and its parent object
2 Views