This thread from 2011 suggested some kind of shell around the channel to include the Peek () function, but it was more a workaround than anything else.
type PeekChanInt struct { in <-chan int out chan int }
General conclusion:
The synchronous channel has no head (it is like a slice of zero length)
You cannot do this because
- a) he returns back to the tail of the line, not to the end, and
- b) the author could get there first, so put can be blocked.
I wanted to use such a feature in the past. This may make sense when there is only one channel consumer (I wanted him to look into the first mouse event to perform a shock test before deciding on its consumption)
You can simulate it using a process acting as an intermediary, but you will have to do this for each type of channel or lose type security.
Remember that there is no buffering, so if you look at a value, you will need to get the value from the other side, which would be equivalent to reading it, but this is wrong because peeking should not have any side effects .
Vonc source share