func processDeadEnv(client apiundertaker.UndertakerClient, clock uc.Clock, tod time.Time, stopCh <-chan struct{}) error { timeDead := clock.Now().Sub(tod) wait := ripTime - timeDead if wait < 0 { wait = 0 } select { case <-clock.After(wait): err := client.RemoveEnviron() return errors.Annotate(err, "could not remove all docs for dead environment") case <-stopCh: return tomb.ErrDying } }