Reputation: 6548
Is it possible to get copy of channel messages? (instead of receive and delete message from channel)
The idea is to log a channel's messages.
Upvotes: 1
Views: 619
Reputation: 79744
No, this is not possible, but you can use two channels, and pass between them observing the data in transit:
func observe(ch interface{}) ch interface{} {
newCh := make(chan interface{})
go func() {
for item := range ch {
fmt.Println(item)
newCh <- item
}
close(newCh)
}()
return newCh
}
Upvotes: 3