For debugging purposes I want to log every element...
# coroutines
r
For debugging purposes I want to log every element going through the channel. Is there any better way to do it than this?
Copy code
class LoggingLinkedListChannel<E>(private val tag: String): LinkedListChannel<E>() {
	override fun offerInternal(element: E): Any {
		println("[$tag] $element")
		return super.offerInternal(element)
	}
}
val chan = LoggingLinkedListChannel<Int>("tag") // was Channel<Int>(Channel.UNLIMITED)
Is it even valid way to do this? It seems to be working for my simple use-case, but still. As another way to do that was trying to get this working with
.map { println(it); it }
, but it throws away capacity as it's effectively creates another channel.
e
That is the way to do it ATM.
r
Okay, thanks for confirmation!