Comment 2 for bug 1468188

Revision history for this message
Dave Cheney (dave-cheney) wrote :

The environ config is not fresh, it comes from the state object that was passed to NewEnvironObserver.

// NewEnvironObserver waits for the environment to have a valid
// environment configuration and returns a new environment observer.
// While waiting for the first environment configuration, it will
// return with tomb.ErrDying if it receives a value on dying.
func NewEnvironObserver(st EnvironConfigObserver) (*EnvironObserver, error) {
        config, err := st.EnvironConfig()
        if err != nil {
                return nil, err
        }
        environ, err := environs.New(config)
        if err != nil {

The config returned from st.EnvironConfig is the State.config field. If you hold a reference to that State value, then you can retrieve the same config that is later retrieved, then mutated,

func (obs *EnvironObserver) loop() error {
        for {
                select {
                case <-obs.tomb.Dying():
                        return nil
                case _, ok := <-obs.environWatcher.Changes():
                        if !ok {
                                return watcher.EnsureErr(obs.environWatcher)
                        }
                }
                config, err := obs.st.EnvironConfig()