Are there any types of streaming data types that I...
# ktor
s
Are there any types of streaming data types that I can get from the Client that can be safely shared and read from concurrently? I think what I’m looking for is something that will replay the already buffered content and will also properly emit to suspended functions when new content is available.
e
Hi @Sam Garfinkel, the
ByteReadChannel
perfectly fits the description 🙂
client.get<ByteReadChannel>(...)
s
It’s safe to call read from multiple coroutines in parallel and they will act correctly? I’m slightly skeptical only because it looks a lot like an InputStream and I wanted to make sure that the cursor is not shared.
e
It's safe to share between threads, but unsafe to read concurrently. What are you expecting from concurrent reading?
s
I’m mostly wondering if there’s a way to do
Copy code
suspend fun foo() = coroutineScope {
    val bar = client.get<..>
    val first = async { bar.readAllButSuspendCoroutineAsNeeded() }
    val second = async { bar.readAllButSuspendCoroutineAsNeeded() }
    println("${first.await()} ${second.await()}")
}
I’d like to have multiple read operations running at once on the same streaming data source. The reason being I’m dealing with an annoyingly large response and I’m trying to optimize the processing of
bar