On Tue, Apr 13, 2021 at 12:53 PM Roman Leventov <leventov...@gmail.com>
wrote:

> type Frame struct{}
>
> type Connection struct {
> sem    *semaphore.Weighted // from http://golang.org/x/sync/semaphore
> mu     sync.Mutex
> frames []*Frame
> }
>
>
My immediate hunch when reading your code was:

type Connection struct {
    frames chan *Frame
}

However, I'm also pretty sure it breaks down in your case. But it might be
good as an exploratory naive question: why wouldn't a channel work in your
case? A Put is to send to the channel. A read is to receive from the
channel. The timeout is handled by a select { ... }, like in your code,
more or less. Granted, you'll have to drain the channel etc, but you
explicitly said the efficiency wasn't that important. And channels tend to
be easier to reason about. My hunch is also this is easier to get a good
semantics for when there are more than 2 goroutines involved.

-- 
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/CAGrdgiWh4%3DjZn9KauSNnTQBaxE3HFLs0h6fRbEhvrH%3D%3Drgj7jQ%40mail.gmail.com.

Reply via email to