should I roll my own copying like with manual canc...
# coroutines
u
should I roll my own copying like with manual cancellation check like this?
Copy code
body.use {
    it.byteStream().use { iss ->
        var bytesCopied: Long = 0
        val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
        var bytes = iss.read(buffer)
        while (bytes >= 0 && coroutineContext.isActive) { <-------------
            ...
            bytesCopied += bytes
            bytes = iss.read(buffer)
        }
        bytesCopied
    }
}
I do get that cancellation is cooperative etc etc — just looking for a idiomatic-retrofit way
y
You could launch a suspend cancellable coroutine, do the work on IO dispatcher, and close the input on cancellation.
u
okay so basically manual coroutine adapter?
y
Jake has a good suggestion below also.
Probably simpler
u
I mean if I remove @Streaming then cancellation works as expected by default, so I kinda think adapter makes it more elegant but sure ill try that one as well