can i poll all items of a buffered channel as a li...
# coroutines
n
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
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
I think you have to do this yourself ATM.
n
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
Perhaps a while true and a break. Or maybe generateSequence and toList.
As long as your channel isn't coming from a flow, I don't think you'll get any face palms lol.