Shutting down goroutines quickly was needed so often that I wrote a package 
to help me with it. it is called idem, short for idempotent.

It uses the idea of an idempotent Close of a channel to signal that the 
goroutine should stop. This is because Go will panic if
close a channel more than once (i.e. you wish to stop a goroutine from more 
than one place).  This is a design flaw in channels, 
but we can work around it by using a mutex.

Since the goroutine that wants the other goroutine to shutdown typically 
needs to wait until that is done, there is a reciprocal
closing of another channel to indicate that the message has been received 
and will be acted on.

https://github.com/glycerine/idem/blob/master/halter_test.go#L43

-- 
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/c5debfad-8dbc-4ae3-9b88-d4b9933d1f1en%40googlegroups.com.

Reply via email to