hey folks question regarding implementation of Kto...
# kotlin-native
i
hey folks question regarding implementation of Ktor http client on iOS https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosClientEngine.kt#L22 and https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosClientEngine.kt#L76 After looking at the source code, am I right that the deserialization of raw bytes (for example via kotlinx.serialization) will be done on the main thread?
s
The second link is the operation queue that URLSession calls back on when the request finishes. It’s pretty normal to use the main queue for that. Currently Coroutines are limited to the main thread in K/N so yes it will happen on the main thread. Many of the pure swift/ObjC apps I’ve worked on in the past have done Json deserialization on the main thread without affecting the responsiveness of the UI. It all depends on how big the payload is.
i
But this depends as you said on size of the payload and seems pretty reasonable to offload this on background thread. JVM impl does this https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-core/jvm/src/io/ktor/client/engine/HttpClientJvmEngine.kt#L14
so the behaviour is totally different on iOS and JVM platforms
s
All true statements but don’t let it hold you back without examining further to see if k/n fits your particular use case.
👍 1