I'm using a library designed around coroutines tha...
# ktor
m
I'm using a library designed around coroutines that also uses ktor so I also have ktor goodies to use. I noticed ktor provides "channels" (
ByteReadChannel
,
ByteWriteChannel
, what's the benefit of them? And what does the following mean?
Operations on this channel cannot be invoked concurrently.
when is a
ByteWriteChannel
more convenient than this?
Copy code
val url = URL(...)
val targetDir = Path.of(...)

withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
  url.openStream().use { stream ->
    Files.copy(stream, targetDir)
  }
}
are they just meant to be used to read and write in chunks without blocking everything else in a thread, and to yield it to other coroutines?
a
They are primitives to work with a stream of bytes in a non-blocking way.