https://kotlinlang.org logo
Title
d

Denys

08/12/2020, 3:11 AM
Hi all! I really need to do the following behavior. There is some source of events, for example, onСlick(), which emits items with time intervals (for example, the user clicks the button very quickly). I need to subscribe to it and collect all items with a set time interval, for example 2 sec. How can this be done with Flow API?
o

octylFractal

08/12/2020, 3:15 AM
val deadline = Instant.now().plusSeconds(2)
val items = flow.takeWhile { Instant.now() < deadline }.toList()
?
or maybe I don't understand exactly what your data looks like
d

Denys

08/12/2020, 3:29 AM
No, I just need to buffer all sent items, like in BroadcastChannel, but using flow
e

ephemient

08/12/2020, 9:45 AM
like this? https://pl.kotl.in/pORqFs8VL (just hacked together, not very tested)