On Thu, Nov 12, 2020 at 9:32 PM 陶青云 <qingyu...@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 <https://xyproblem.info/>. > 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/CABx2%3DD-wPzNcgS4raZG96yPxc2J2wd6LvYmtLUspksoSBu9aUA%40mail.gmail.com.