In my experience, most API's can take a 'done' channel, usually like context.Context's, to stop it. And, in general, creators of resources (channels, in this case), should also release that resource. This is closely tied to the done channel.
So, instead of the function creating a done channel, which is closed by the caller, the caller passes in the done channel, and closes it when it wants the function to stop. This removes the secondary purpose of the queue channel also being kind of a close purpose in addition to sending data. This also flows with creators of a channel being the writers to it. (I did keep errors the same, though.)
main.go:
the old check for no arguments did nothing. The flags will never be nil because they have defaults. So, check the default values of the flags to see if both are effectively unset.
typo
removed a 'new' and just use the normal go initialize
put waiting for the signal in the select. We might get an extra loop in without the extra goroutine, but the code is cleaner, and I could barely kill it in time as it was. spaces
In my experience, most API's can take a 'done' channel, usually like context.Context's, to stop it. And, in general, creators of resources (channels, in this case), should also release that resource. This is closely tied to the done channel.
So, instead of the function creating a done channel, which is closed by the caller, the caller passes in the done channel, and closes it when it wants the function to stop. This removes the secondary purpose of the queue channel also being kind of a close purpose in addition to sending data. This also flows with creators of a channel being the writers to it. (I did keep errors the same, though.)
main.go: