Esempio n. 1
0
// Stop stops the watcher. If an error is returned by the
// watcher, t is killed with the error.
func Stop(w Stopper, t *tomb.Tomb) {
	if err := w.Stop(); err != nil {
		if err != tomb.ErrStillAlive && err != tomb.ErrDying {
			// tomb.Kill() checks for the two errors above
			// by value, so we shouldn't wrap them, but we
			// wrap any other error.
			err = errors.Trace(err)
		}
		t.Kill(err)
	}
}
Esempio n. 2
0
// delayedTomb returns a tomb that starts dying a given duration
// after t starts dying.
func delayedTomb(t *tomb.Tomb, d time.Duration) *tomb.Tomb {
	var delayed tomb.Tomb
	go func() {
		select {
		case <-t.Dying():
			time.Sleep(d)
			delayed.Kill(nil)
		case <-delayed.Dying():
			return
		}
	}()
	return &delayed
}
Esempio n. 3
0
// propagateTearDown tears down the handler, but ensures any error is
// propagated through the tomb's Kill method.
func propagateTearDown(handler tearDowner, t *tomb.Tomb) {
	if err := handler.TearDown(); err != nil {
		t.Kill(err)
	}
}
Esempio n. 4
0
// Stop stops the watcher. If an error is returned by the
// watcher, t is killed with the error.
func Stop(w Stopper, t *tomb.Tomb) {
	if err := w.Stop(); err != nil {
		t.Kill(err)
	}
}
Esempio n. 5
0
// TearDown the handler, but ensure any error is propagated
func handlerTearDown(handler WatchHandler, t *tomb.Tomb) {
	if err := handler.TearDown(); err != nil {
		t.Kill(err)
	}
}