https://kotlinlang.org logo
#coroutines
Title
# coroutines
r

r4zzz4k

01/26/2018, 5:02 PM
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

elizarov

01/26/2018, 6:59 PM
That is the way to do it ATM.
r

r4zzz4k

01/26/2018, 7:00 PM
Okay, thanks for confirmation!
3 Views