jared
11/18/2020, 5:53 PMkotlinx.coroutines
1.3.9-native-mt-2
and Ktor 1.4.2
in a multiplatform library for sharing networking between iOS and Android. I am confused over Ktor and background threads. I am using the Main
dispatcher and I can’t tell if the network request is running on the main thread or a background thread. Does Ktor handle running a single background thread for me?John O'Reilly
11/18/2020, 6:10 PMjared
11/18/2020, 6:30 PMJohn O'Reilly
11/18/2020, 6:31 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
under the hoodDaniele B
11/18/2020, 6:39 PMJohn O'Reilly
11/18/2020, 6:39 PMDaniele B
11/18/2020, 6:49 PMJohn O'Reilly
11/18/2020, 6:50 PMjared
11/18/2020, 6:51 PMwithContext(<http://Dispatches.IO|Dispatches.IO>)
because StrictMode was complaining about reading from disk when the Ktor HttpClient
was initialized. That confused me, but if Ktor was running the request on the main thread then I would assume a NetworkOnMainThread exception would be thrown.John O'Reilly
11/18/2020, 6:51 PMDaniele B
11/18/2020, 6:55 PMJohn O'Reilly
11/18/2020, 7:05 PM[main] INFO io.ktor.client.HttpClient - REQUEST: <http://api.open-notify.org/astros.json>
[main] INFO io.ktor.client.HttpClient - METHOD: HttpMethod(value=GET)
[main] INFO io.ktor.client.HttpClient - COMMON HEADERS
[main] INFO io.ktor.client.HttpClient - -> Accept: application/json
[main] INFO io.ktor.client.HttpClient - -> Accept-Charset: UTF-8
[main] INFO io.ktor.client.HttpClient - CONTENT HEADERS
[main] INFO io.ktor.client.HttpClient - BODY Content-Type: null
[main] INFO io.ktor.client.HttpClient - BODY START
[main] INFO io.ktor.client.HttpClient -
[main] INFO io.ktor.client.HttpClient - BODY END
[main] INFO io.ktor.client.HttpClient - RESPONSE: 200 OK
[main] INFO io.ktor.client.HttpClient - METHOD: HttpMethod(value=GET)
[main] INFO io.ktor.client.HttpClient - FROM: <http://api.open-notify.org/astros.json>
[main] INFO io.ktor.client.HttpClient - COMMON HEADERS
[main] INFO io.ktor.client.HttpClient - -> Connection: keep-alive
[main] INFO io.ktor.client.HttpClient - -> Content-Length: 356
[main] INFO io.ktor.client.HttpClient - -> Content-Type: application/json
[main] INFO io.ktor.client.HttpClient - -> Date: Wed, 18 Nov 2020 19:04:33 GMT
[main] INFO io.ktor.client.HttpClient - -> Server: nginx/1.10.3
[main] INFO io.ktor.client.HttpClient - -> access-control-allow-origin: *
[ktor-apache-dispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY Content-Type: application/json
[ktor-apache-dispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY START
[ktor-apache-dispatcher-worker-2] INFO io.ktor.client.HttpClient - {"message": "success", "number": 7, "people": [{"craft": "ISS", "name": "Sergey Ryzhikov"}, {"craft": "ISS", "name": "Kate Rubins"}, {"craft": "ISS", "name": "Sergey Kud-Sverchkov"}, {"craft": "ISS", "name": "Mike Hopkins"}, {"craft": "ISS", "name": "Victor Glover"}, {"craft": "ISS", "name": "Shannon Walker"}, {"craft": "ISS", "name": "Soichi Noguchi"}]}
[ktor-apache-dispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY END
main
but then actualy request is made on ktor-apache-dispatcher-worker-2
Daniele B
11/18/2020, 7:10 PMJohn O'Reilly
11/18/2020, 7:12 PMjared
11/18/2020, 7:17 PMHttpRequestBuilder
running on main.Daniele B
11/18/2020, 7:24 PMAmritansh
11/19/2020, 12:37 AM