`HttpClient` extends `CoroutineScope`. Is it safe ...
# ktor
e
HttpClient
extends
CoroutineScope
. Is it safe and recommended to use this scope to launch coroutines, e.g. to implement logic tied to the client's lifecycle?
I would assume so, based on the ktor server application documentation: https://github.com/ktorio/ktor/blob/a2e934dc42553da4a43d4bb1c1806cfaeed5fa93/ktor-server/ktor-server-core/jvmAndNix/src/io/ktor/server/application/Application.kt#L82-L83
It is also the application coroutine scope that is cancelled immediately at application stop so useful for launching background coroutines.
My assumption is that the design of the
HttpClient
being a
CoroutineScope
behaves similarly: as long as its scope isn't cancelled, it could actually be the best place to launch your coroutines?
a
Is it safe and recommended to use this scope to launch coroutines, e.g. to implement logic tied to the client's lifecycle?
Yes.
e
Thanks!
I had this approach working, but I wondered if it was good practice