In golang from one go routine I'm posting message to a buffered channel. But my reader go routine may be little slow in processing, and any read from the channel may not happen faster. So to stop the channel buffer getting filled up I dont want the same data to be posted again in the buffered channel. Is there a way to do that?
Asked
Active
Viewed 375 times
-2
-
1There is nothing in channels to do that for you, you'll have to implement it yourself. We can't help further without a specific problem and sample code. – Marc Jun 04 '20 at 09:00
-
One can implement [pipelines of channels](https://blog.golang.org/pipelines) in Go. Writing one that eliminates duplicates could be useful. Could you provide some code showing the type of data in the channel and how the channel is used? Do you want to eliminate just adjacent duplicates or as many duplicates as possible, maybe by keeping a record of all previous values? – Mark Plotnick Jun 04 '20 at 17:12
1 Answers
2
Is there a way to do that?
No.
Channels (buffered or not) are opaque and you can do nothing but send or receive from them, they provide absolutely no further logic.

Volker
- 40,468
- 7
- 81
- 87