rt
06/07/2020, 7:13 AMwhile (...) { delay(1000); emit(buffer); buffer.clear() }
to have timed buffering. I'm aware there are operators for this, just trying to figure things out for myself.
Also, any other notes on pitfalls of my implementation would be appreciated.fatih
06/07/2020, 9:49 AMStateFlow
. By the way can you give a bit more details about use case and why do you need to clear buffer?rt
06/07/2020, 9:51 AMfatih
06/07/2020, 9:56 AMrt
06/07/2020, 9:57 AMfatih
06/07/2020, 12:12 PMval scope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>)
val testFlow = flow {
repeat(5) {
emit(it)
}
}
scope.launch {
testFlow
.collect {
// Check your condition about when to cancel
// After you call cancel, isActive becomes false
if (it == 2) cancel()
// If this coroutine is active do your thing
if (isActive) {
println(it)
}
}
}
rt
06/07/2020, 12:14 PMwhile (isActive)
part. Not sure how efficient this is now, but anyway: https://pl.kotl.in/fJNkH2kWcZach Klippenstein (he/him) [MOD]
06/07/2020, 2:05 PMn
elements and then timeout, you'll send the buffer but also send an empty list after the timeout.rt
06/07/2020, 3:49 PMZach Klippenstein (he/him) [MOD]
06/07/2020, 5:07 PMrt
06/07/2020, 6:57 PMless allocations
> more allocations
.
i'm still on the fence wrt intermediate stream anyway, but think i can rely on fusion here. probably should benchmark anywayZach Klippenstein (he/him) [MOD]
06/07/2020, 7:11 PMrt
06/08/2020, 6:58 AM