*: rename watcher to watchStream

Watcher vs Watching in storage pkg is confusing. Watcher should be named
as watchStream since it contains a channel as stream to send out events.
Then we can rename watching to watcher, which actually watches on a key
and send watched events through watchStream.

This commits renames watcher to watchStram.
This commit is contained in:
Xiang Li
2016-01-02 15:59:32 -08:00
parent 41771d9522
commit ee0b3f42ed
10 changed files with 38 additions and 38 deletions

View File

@@ -34,10 +34,10 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) error {
closec := make(chan struct{})
defer close(closec)
watcher := ws.watchable.NewWatcher()
defer watcher.Close()
watchStream := ws.watchable.NewWatchStream()
defer watchStream.Close()
go sendLoop(stream, watcher, closec)
go sendLoop(stream, watchStream, closec)
for {
req, err := stream.Recv()
@@ -57,7 +57,7 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) error {
toWatch = creq.Prefix
prefix = true
}
watcher.Watch(toWatch, prefix, creq.StartRevision)
watchStream.Watch(toWatch, prefix, creq.StartRevision)
default:
// TODO: support cancellation
panic("not implemented")
@@ -65,10 +65,10 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) error {
}
}
func sendLoop(stream pb.Watch_WatchServer, watcher storage.Watcher, closec chan struct{}) {
func sendLoop(stream pb.Watch_WatchServer, watchStream storage.WatchStream, closec chan struct{}) {
for {
select {
case evs, ok := <-watcher.Chan():
case evs, ok := <-watchStream.Chan():
if !ok {
return
}
@@ -90,7 +90,7 @@ func sendLoop(stream pb.Watch_WatchServer, watcher storage.Watcher, closec chan
case <-closec:
// drain the chan to clean up pending events
for {
_, ok := <-watcher.Chan()
_, ok := <-watchStream.Chan()
if !ok {
return
}