can i poll all items of a buffered channel as a list ?
my intent is to ingest events into a buffered channel
and at a set rate bulk insert all that are currently in the buffered channel
is that the correct way to handle this or is there cleaner constructs provided by coroutines that i am missing ?
one of the requirements is that inserting events should cause backpressure
Nikky
12/03/2020, 3:29 PM
my code currently looks like so:
Copy code
@OptIn(ExperimentalStdlibApi::class)
val wrappedEvents = buildList {
// collect all events in ingestChannel until empty
do {
val ingested = ingestChannel.poll()
if (ingested != null) {
add(ingested)
}
} while (ingested != null)
}
// processing events afterwards
d
Dominaezzz
12/03/2020, 3:32 PM
I think you have to do this yourself ATM.
n
Nikky
12/03/2020, 3:33 PM
i am mostly just asking to have some more experienced people have a glance and tell me if i am doing something truly stupid, if there is no facepalm reactions then all is good
d
Dominaezzz
12/03/2020, 3:38 PM
Perhaps a while true and a break. Or maybe generateSequence and toList.
Dominaezzz
12/03/2020, 3:38 PM
As long as your channel isn't coming from a flow, I don't think you'll get any face palms lol.