Long story short:
- How do you clean up main loops in libraries?
- How do you test code that uses SetFinalizer()?
Sometimes I use the "main loop" paradigm to make an object safe for
concurrent use. Basically, you have a New() routine that creates a new
object and starts a main loop in a goroutine. This main loop listens for
operations on a channel and you expose that channel directly (or indirectly
using accessor methods) to the user.
How do you clean this up when the object is no longer used? A .Close()
method works. I'd rather avoid that if I can, because .Close is extra work
(at the risk of forgetting it) for the user.
Ideally I'd like to stop the main loop once the garbage collector reclaims
Now I have something which *I think* works: how do I test it? It's a tricky
system and the tests I wrote succeed on my machine, but on Travis-CI not
even the simplest use of .SetFinalizer ever does anything.
Do I just leave it in and assume that because it works here, it works
Or does using a main loop like this require users to .Close()? Then I'd
rather use a lock.
Here is Travis not running any finalizers (not even a very simple one on an
This test passes every single time on my box. I tried crazy stuff to get
the GC juices flowing, to no avail.
It's a stripped down version of this project:
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 [email protected].
For more options, visit https://groups.google.com/d/optout.