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

napperley

05/13/2019, 7:20 AM
Is it possible to cancel a long running HTTP request without having a exception thrown?
e

e5l

05/13/2019, 7:21 AM
Hi @napperley, you can try
withTimeoutOrNull
n

napperley

05/13/2019, 11:08 PM
Is there is no way to manually to cancel a request without a timeout occurring?
With the
Job
I used a
isActive
property check along with a
cancel
function call, eg:
Copy code
if (refreshJob != null && refreshJob!!.isActive) {
    refreshJob?.cancel(CancellationException("Refresh cancelled by user"))
    refreshJob = null
    // ...
}
e

e5l

05/14/2019, 7:49 AM
Yep. And you can get response job in client like this:
myHttpResponse.coroutineContext[Job]
👍 1
141 Views