init cancel watcher

This commit is contained in:
Xiang Li
2013-12-26 22:06:15 +08:00
parent c36f306a1d
commit 5e499456f0
7 changed files with 66 additions and 51 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().NewWatcher(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().NewWatcher(key, recursive, sinceIndex)
if err != nil {
return etcdErr.NewError(500, key, s.Store().Index())
}
@@ -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