Closed as not planned
Closed as not planned
Description
When used with retrofit/okhttp/okio stack, reading and writing bytes becomes
val source = api.download("..").source()
source.use { it.readAll(sink) }
However the read/writes become blocking and non cancellable. Fortunatelly okio checks for java thread interrupts, so runInterruptible
can be used
val source = api.download("..").source()
runInterruptible {
source.use { it.readAll(sink) }
}
However, okio throws java.io.InterruptedIOException
, which the runInterruptible
doesn't then repackage as CancellationException
Should be repackage this exception as well?
private fun <T> runInterruptibleInExpectedContext(coroutineContext: CoroutineContext, block: () -> T): T {
try {
val threadState = ThreadState(coroutineContext.job)
threadState.setup()
try {
return block()
} finally {
threadState.clearInterrupt()
}
} catch (e: InterruptedException) { <----------------------
throw CancellationException("Blocking call was interrupted due to parent cancellation").initCause(e)
}
}
Metadata
Metadata
Assignees
Labels
No labels