https://kotlinlang.org logo
#ktor
Title
# ktor
b

Brendan Weinstein

12/12/2019, 3:49 AM
For use of the ktor client within an android app should we ever close the client? https://ktor.io/clients/http-client/call/requests.html For okhttp, we typically reuse one instance of the client throughout the app. Both clients have an initialization cost. Given that cost, it makes sense to me to leave the ktor client open for an application session. Are there any potential consequences?
e

e5l

12/12/2019, 4:38 AM
Hi @Brendan Weinstein, Yes, you should do it when you don’t need new requests. All fired requests will be executed.
b

Brendan Weinstein

12/12/2019, 4:41 AM
@e5l What is the purpose of closing? If we have a set of requests [A, B, C] that we fire off. We receive responses the same second. 1 minute goes by and we fire off requests [C, D, E]. Are you suggesting I should close the client and re-open (or just get a new instance of HttpClient)?
e

e5l

12/12/2019, 6:00 AM
Nope, feel free to keep it open if you need it. Closing is mostly about gracefully termination: when you need to shutdown the app and want to make sure that there are no other requests
👍 1
3 Views