Skip to content

Commit

Permalink
Merge pull request #27 from abronan/etcd_watch_fix
Browse files Browse the repository at this point in the history
Correct misplaced calls to Get/List in Watch/WatchTree for etcd
  • Loading branch information
abronan committed Jul 20, 2015
2 parents 057813e + 0ef5c8a commit 15aa29c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions store/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ func (s *Etcd) Exists(key string) (bool, error) {
// be sent to the channel. Providing a non-nil stopCh can
// be used to stop watching.
func (s *Etcd) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) {
// Get the current value
current, err := s.Get(key)
if err != nil {
return nil, err
}

// Start an etcd watch.
// Note: etcd will send the current value through the channel.
etcdWatchCh := make(chan *etcd.Response)
Expand All @@ -212,6 +206,12 @@ func (s *Etcd) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair,
go func() {
defer close(watchCh)

// Get the current value
current, err := s.Get(key)
if err != nil {
return
}

// Push the current value through the channel.
watchCh <- current

Expand Down Expand Up @@ -243,12 +243,6 @@ func (s *Etcd) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair,
// will be sent to the channel .Providing a non-nil stopCh can
// be used to stop watching.
func (s *Etcd) WatchTree(directory string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
// Get child values
current, err := s.List(directory)
if err != nil {
return nil, err
}

// Start the watch
etcdWatchCh := make(chan *etcd.Response)
etcdStopCh := make(chan bool)
Expand All @@ -260,6 +254,12 @@ func (s *Etcd) WatchTree(directory string, stopCh <-chan struct{}) (<-chan []*st
go func() {
defer close(watchCh)

// Get child values
current, err := s.List(directory)
if err != nil {
return
}

// Push the current value through the channel.
watchCh <- current

Expand Down

0 comments on commit 15aa29c

Please sign in to comment.