anybody know if there's a way to get a kotlinx io ...
# ktor
e
anybody know if there's a way to get a kotlinx io
Source
from a
ByteReadChannel
?
j
Seems impossible. You could go the other way, though.
The only option I see would be to use
runBlocking
which is bad because the
Source
could already be inside a coroutine on an IO thread. And you're not supposed to do that.
The API contract of
RawSource.read
is that it will obtain at least a single byte, and that requires blocking which an async mechanism just can't fulfill.
e
for now i'm just gonna try this
Untitled
j
Okio has a
Pipe
which is closer to what's needed here
e
this is not a pipe
(sorry)
j
it doesn't even register as strange with me anymore. i just know your flavor of english will contain these references
🎉 1
en_US-Denman
e
Locale me Maybe
j
I could see kotlinx.io getting some sort of suspension-based, pipe-like type in the future so that one coroutine could be consuming a bunch of data sources (like http/2 streams) and writing them into these pipes for individual consumers to suspend and wait for chunks as segments although not sure how you make all the nice Source APIs work such that when there's a byte underflow they suspend. seems like maybe you'd be able to require so many bytes in a Buffer or something and then you get to non-blocking read from that until you decide to wait or hit EOF and have to wait
e
mmm yeah
a
You can follow this feature request.