Try to use two channels: one to signal that the receiver needs a new value and another one to send new value to the receiver. Supposedly the sender won't block if you're using `select` to check what receivers need values, and the receiver can block until a new value is arrived at the input channel.
However as others pointed out, if you're experiencing resistance from the framework, it might indicate that you are trying to implement some less than idiomatic approach and perhaps an overhaul of this approach might be more beneficial. Hope this helps. пт, 13 нояб. 2020 г. в 09:12, 陶青云 <qingyu...@gmail.com>: > > > It is not a one-length buffered channel. I need to drop because the > recveiver do heavy work that can't process as quickly as sender. > 在2020年11月13日星期五 UTC+8 下午2:36:13<Kurtis Rader> 写道: >> >> On Thu, Nov 12, 2020 at 9:32 PM 陶青云 <qing...@gmail.com> wrote: >>> >>> Thanks. I want the receiver always get the relately new vaule, I don't >>> want the sender blocked and I either choose drop the current value or the >>> first value of the channel. But I don't find a way to safely drop the first >>> value from the channel. >> >> >> You seem to be talking about a buffered channel of length one. If that is >> true why are you using a channel? You can instead use a simple var protected >> by a mutex. If you're talking about a buffered channel with size greater >> than one it is unclear why a full channel should drop the first entry in the >> channel rather than multiple (even all) entries in the queue. This seems >> like an XY problem. >> >>> >>> Maybe like this ? >> >> >> No, since that "solution" just replaces one race with another. >> >> -- >> Kurtis Rader >> Caretaker of the exceptional canines Junior and Hank > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/5f5cb0c2-54e9-4d5f-bbc7-43c902615b8fn%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMteYTbf6Ly-th4KvZcR10xOEKFUPU5tDK44PLTTDwVr6x6vEw%40mail.gmail.com.