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
e5l
03/25/2020, 6:50 PM
Hi @Sam Garfinkel, the
ByteReadChannel
perfectly fits the description 🙂
e5l
03/25/2020, 6:51 PM
client.get<ByteReadChannel>(...)
s
Sam Garfinkel
03/25/2020, 6:51 PM
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
e5l
03/25/2020, 6:52 PM
It's safe to share between threads, but unsafe to read concurrently. What are you expecting from concurrent reading?
s
Sam Garfinkel
03/25/2020, 7:00 PM
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()}")
}
Sam Garfinkel
03/25/2020, 7:01 PM
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