func (t *Tomb) Done() {
	t.Kill(nil)
	close(t.dead)
}
Done flags the goroutine as dead, and should be called a single time
right before the goroutine function or method returns.
If the goroutine was not already in a dying state before Done is
called, it will be flagged as dying and dead at once with no
error.
package tomb
import (
	"errors"
	"fmt"
	"sync"
)
type Tomb struct {
	m      sync.Mutex
	dying  chan struct{}
	dead   chan struct{}
	reason error
}
var (
	ErrStillAlive = errors.New("tomb: still alive")
	ErrDying = errors.New("tomb: dying")
)
func (t *Tomb) init() {
	t.m.Lock()
	if t.dead == nil {
		t.dead = make(chan struct{})
		t.dying = make(chan struct{})
		t.reason = ErrStillAlive
	}
	t.m.Unlock()
}
func (t *Tomb) Dead() <-chan struct{} {
	t.init()
	return t.dead
}
func (t *Tomb) Dying() <-chan struct{} {
	t.init()
	return t.dying
}
func (t *Tomb) Wait() error {
	t.init()
	<-t.dead
	t.m.Lock()
	reason := t.reason
	t.m.Unlock()
	return reason
}