Merge pull request #418 from xiangli-cmu/cancel_watcher

cancel watcher
This commit is contained in:
Xiang Li
2014-01-08 21:34:32 -08:00
7 changed files with 98 additions and 67 deletions

View File

@@ -25,11 +25,11 @@ func WatchKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
}
// Start the watcher on the store.
c, err := s.Store().Watch(key, false, sinceIndex)
watcher, err := s.Store().Watch(key, false, sinceIndex)
if err != nil {
return etcdErr.NewError(500, key, s.Store().Index())
}
event := <-c
event := <-watcher.EventChan
// Convert event to a response and write to client.
b, _ := json.Marshal(event.Response(s.Store().Index()))

View File

@@ -55,7 +55,7 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
}
// Start the watcher on the store.
eventChan, err := s.Store().Watch(key, recursive, sinceIndex)
watcher, err := s.Store().Watch(key, recursive, sinceIndex)
if err != nil {
return err
}
@@ -65,8 +65,9 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
select {
case <-closeChan:
watcher.Remove()
return nil
case event = <-eventChan:
case event = <-watcher.EventChan:
}
} else { //get