Nikky
12/15/2020, 9:57 AMMarc Knaup
12/15/2020, 10:00 AMCopyOnWriteArrayList
? It uses regular thread locking, not coroutine-based locking.Nikky
12/15/2020, 10:11 AMMarc Knaup
12/15/2020, 10:12 AMNikky
12/15/2020, 10:15 AMMarc Knaup
12/15/2020, 10:18 AMFlow<T>
internally to chunking Flow<Any?>
that collects all upstream elements in a list.
In a separate coroutine you run your timer that periodically throws a Flush
object into the Flow<Any?>
. Once that chunking Flow encounters the Flush
object you simply send the list and create a new empty list.
No locking needed.Nikky
12/15/2020, 10:19 AMMarc Knaup
12/15/2020, 10:19 AMA, B, C, …, D
-> A, B, C, Flush, D, Flush
-> [A, B, C], [D]
Nikky
12/15/2020, 10:19 AMMarc Knaup
12/15/2020, 10:20 AMNikky
12/15/2020, 10:20 AMMarc Knaup
12/15/2020, 10:21 AMFlow
with a SharedFlow
maybe.Marc Knaup
12/15/2020, 10:21 AMMarc Knaup
12/15/2020, 10:22 AMflatMapConcat
Marc Knaup
12/15/2020, 10:23 AMMarc Knaup
12/15/2020, 10:23 AMMarc Knaup
12/15/2020, 10:26 AMFlow
that periodically emits but I cannot find it.Nikky
12/15/2020, 10:34 AMNikky
12/15/2020, 10:36 AMMarc Knaup
12/15/2020, 10:38 AMNikky
12/15/2020, 10:40 AMdelayMillis
passed
reset the timer after emit
emprty chunks are not emittedMarc Knaup
12/15/2020, 10:42 AMNikky
12/15/2020, 10:42 AMNikky
12/15/2020, 10:44 AMstartTimer()
launch block currently
val toSend = if (toSend.isNotEmpty()) {
toSend
} else {
null
}
if(toSend != null) {
channel.send(toSend)
}
the reason this is split up is because i cannot call suspend functions inside a critical section like withLocak apparentlyMarc Knaup
12/15/2020, 11:06 AMMarc Knaup
12/15/2020, 11:07 AMMarc Knaup
12/15/2020, 11:08 AMNikky
12/15/2020, 11:22 AMMarc Knaup
12/15/2020, 11:23 AMtimerFlow
Marc Knaup
12/15/2020, 11:24 AMMarc Knaup
12/15/2020, 11:24 AMMarc Knaup
12/15/2020, 11:25 AMNikky
12/15/2020, 11:28 AMMarc Knaup
12/15/2020, 11:29 AMMarc Knaup
12/15/2020, 11:29 AMNikky
12/15/2020, 11:30 AMMarc Knaup
12/15/2020, 11:32 AMNikky
12/15/2020, 11:34 AMMarc Knaup
12/15/2020, 11:35 AMMarc Knaup
12/15/2020, 11:36 AMNikky
12/15/2020, 11:36 AMMarc Knaup
12/15/2020, 11:37 AMNikky
12/15/2020, 11:41 AMMarc Knaup
12/15/2020, 11:42 AMMarc Knaup
12/15/2020, 11:42 AMMarc Knaup
12/15/2020, 11:42 AMMarc Knaup
12/15/2020, 11:43 AMNikky
12/15/2020, 11:54 AMCircusmagnus
12/16/2020, 12:34 PM