Funny that chunked question just came up. I'm working on a small impl myself, and had a question on it. https://github.com/Kotlin/kotlinx.coroutines/pull/1558/files#diff-aa50430f04c34e0e106abd538b1918fcR84 If the upstream flow throws an exception, I want to go ahead and flush the buffered results, then rethrow the exception. I dont think this code does that, and I'm struggling to find the right way to accomplish it cleanly.
Actually: Asking the question publicly always helps. 🙂 In my equivalent to the chucked in the PR, I added a catch in front that flushes the buffer and rethrows.
Copy code
outsideFlow.catch {
if (data.isNotEmpty()) {
emit(data.toList())
data.clear()
}
throw it
}