Hi, is there a way to use Ktor 1.6.7 with Coroutin...
# ktor
d
Hi, is there a way to use Ktor 1.6.7 with Coroutines 1.6.0-RC2 on Kotlin/Native to take advantage of the new memory model? I get an error when I try to use the HttpClient on iOS, which is thrown by this function which is called in the init block of HttpClient. Looks like I’m not able to use a Coroutines version different than a
native-mt
one
h
Currently, you can only use Ktor with a
native-mt
version, which will be published after
1.6.0
official release. There is wip to support non native-mt version: https://github.com/ktorio/ktor/tree/e5l/coroutines
d
I see, thanks! I tried with coroutines
1.5.2-native-mt
, and now the only limitation on iOS is that suspend functions must be called from the main thread
r
I use
Copy code
kotlin = "1.6.0"
coroutines = "1.6.0-RC"
ktorVer = "1.6.2-native-mm-eap-196"
with
Copy code
# enable new native memory model
kotlin.native.binary.memoryModel=experimental
kotlin.native.binary.freezing=disabled
and it works all fine
👀 1
j
One small gotcha with that version of ktor is that it doesn't support M1.... that support was added I think in 1.6.5
d
thanks guys. @rudolf.hladik do you get the
Calling Kotlin suspend functions from Swift/Objective-C is currently supported only on main thread
error with this setup? I just tried with your configuration but coroutines 1.6.0-RC2 and I’m still getting the error. Btw Kotlin 1.6.10 has just been released 😄
h
This is still required.
r
I don’t get this error beacause I use Arkitekt usecases library, for K1.6 and new native MM use version
0.2.0-SNAPSHOT-MM
. But you can basically use something like this
Copy code
fun <T> execute(scope: CoroutineScope, suspendBlock: suspend ()-> T, onSuccess: (T) -> Unit, onError: (Throwable) -> Unit): Job {
    // launch on main dispatcher
    return scope.launch {
        runCatching {
            suspendBlock() // suspend block can be called on different dispatcher
        }.fold(onSuccess,onError) // onSuccess, onError called on main
    }
}