7 comments

[ 6.1 ms ] story [ 33.5 ms ] thread
Could you implement this with a linked list underneath to remove the max queue size?
So a mutex-protected list that feeds the queue?
Or just have each goroutine read from a shared channel. From what I understand they are thread safe (granted I'm not a go person) and then expose the channel ass the method for adding.

So all of the threads just read from the channel and rather then adding to a queue you write to the gochannel they are all reading from.

Maybe I'm missing something, but that is how I'm doing it. The Queue struct has a 'Queue.Jobs chan string' that is the public method for adding to the "Queue" and then the go worker()'s read from that buffered channel.

Basically, this simple Queue just adds some niceties around a buffered channel X number of go func() are reading from.

Ok well then can you back it by a linked list? That way there is no size.
Channels are inherently FIFO queues. So why not just use the usual `select`/`case` method and cast the `struct` you need into a chan with `make(chan, struct)`?

See: https://gobyexample.com/non-blocking-channel-operations

Are you talking about doing this instead of buffering the channel? The reason I buffer it is because I don't want whatever is providing the worker with a message to block while waiting to send to the workers.