Thoughts on this extension method to java.util.Que...
# codereview
d
Thoughts on this extension method to java.util.Queue?
Copy code
private inline fun <T : Any> Queue<T>.drain(callback: (T) -> Unit) {
   while (true) poll()?.also(callback) ?: break
}
d
Yes, I’m not copying the data, I’m processing it in place.
I realized what I really need for my use case is a MPSC queue.
a
Maybe take a look at Channels
d
This is not in a suspend context.
k
You can use
forEach
instead of inventing your own.
d
You do understand poll() has side effects right?
k
Ah, of course, my mistake.
👍 1
d
Sorry my reply was a harsh. I could have said that better.