
Show HN: Super Simple Worker Queue in Go - Xeoncross
https://github.com/Xeoncross/goworkqueue
======
kixpanganiban
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](https://gobyexample.com/non-blocking-channel-operations)

~~~
Xeoncross
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.

------
gravypod
Could you implement this with a linked list underneath to remove the max queue
size?

~~~
Xeoncross
So a mutex-protected list that feeds the queue?

~~~
gravypod
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.

~~~
Xeoncross
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.

~~~
gravypod
Ok well then can you back it by a linked list? That way there is no size.

