Ejemplo n.º 1
0
// WaitForEnviron waits for an valid environment to arrive from
// the given watcher. It terminates with tomb.ErrDying if
// it receives a value on dying.
func WaitForEnviron(w *state.EnvironConfigWatcher, dying <-chan struct{}) (environs.Environ, error) {
	for {
		select {
		case <-dying:
			return nil, tomb.ErrDying
		case config, ok := <-w.Changes():
			if !ok {
				return nil, watcher.MustErr(w)
			}
			environ, err := environs.New(config)
			if err == nil {
				return environ, nil
			}
			log.Errorf("worker: loaded invalid environment configuration: %v", err)
			loadedInvalid()
		}
	}
}
Ejemplo n.º 2
0
func stopWatcher(c *C, w *state.EnvironConfigWatcher) {
	err := w.Stop()
	c.Check(err, IsNil)
}