How do you, from a coroutine A, run something on a...
# kotlin-native
r
How do you, from a coroutine A, run something on another thread (a Ktor request or any coroutine B) and suspend while waiting for the result, without freezing coroutine A, using 1.3.9-native-mt?
👀 1
k
Channel? what kind of processing do you expect to happen on thread A?
r
I just want the freezing virus to stop contaminating my entire app
When I do a Ktor request it freezes my coroutine, I want to isolate that call so that it stops doing that
k
ohhh, that kind of freezing
r
@e5l can you help us with this please?
e
Could you try executing ktor request in the sepearate
launch {}
?
l
@rudolf.hladik If you're using a
CoroutineExceptionHandler
, it might be the cause of the issue.
That was the issue Gael was encountering FYI.
r
I’m not using CEH
@e5l you mean like this?
Copy code
suspend fun getDevice(onSuccess: (Device) -> Unit): Unit = withContext(workerDispatcher) {
        launch {
            val device = HttpClient().use { httpClient ->
                httpClient.get<String>(url)
                    .let { response ->
                        json.decodeFromString(Device.serializer(), response)
                    }
            }
            onSuccess(device)
        }
    }
l
@rudolf.hladik Did you try running ktor code exclusively on
Dispatchers.Main
?
r
yep, it’s working fine, even with
withContext(Dispatchers.Main)
r
Ktor Client 1.4.1 cannot run outside the main thread
r
I don’t think so, why it would benefit from mt coroutines than
l
To switch dispatchers internally @rudolf.hladik.
k
i am using Ktor from non-main threads
l
… successfully?
k
that's hard to answer
mostly no
r
do you have some snippet to share?
k
i do not
r
😞
k
at this point I generally recommend that people don't try to use it in production. it's too unreliable.
r
@louiscad so the Ktor makes sure to run the requests on non-main thread by itself so we don’t have to care about it? I haven’t seen such usecase
l
@rudolf.hladik it uses callback based APIs and avoids blocking the main thread.