The functionality is still exactly the same, but the API was changed
in the following ways:
- Renamed Fatal and Fatalf to Kill and Killf.
- The Stop error value is gone. Use nil instead.
- The Err method will now return ErrStillRunning if the goroutine
isn't dead yet, which means a nil return reflects an actual nil Kill call.
- Make zero-value of Tomb good to use, and as a consequence, make
Dead and Dying into methods rather than fields.
The blog post describing the package lives at:
http://blog.labix.org/2011/10/09/death-of-goroutines-under-control
It hasn't been updated with the new API yet, but will be.
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog
-- I'm not absolutely sure of anything.
I am not sure about the reason, but could it be because the property of
struct{} taking up no room?
M;
The values themselves are not important for these two channels, as
they are used merely to flag an event. Besides taking no space,
struct{} informs more realistically the fact there's no actual data
being informed via the channel.
It's useful that Dead() returns a channel so it's easy and cheap to
wait in a select for the tomb to finish.
However although the documentation refers to a single goroutine,
it's easy to use it for a collection of goroutines by using a WaitGroup
alongside it.
for example: http://play.golang.org/p/Xh7qWsDPZP
(wouldn't it be nice if play.golang.org knew about external packages?!)
I'll put the example onto the tomb package itself so that it's visible
in the documentation.
Thanks for suggesting, and thanks to Roger for the sample.