// 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) } }
// 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 }
// 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) } }
// 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) } }
// 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) } }