small fix

This commit is contained in:
yangzhouhan
2015-08-06 19:15:11 -07:00
parent 83e023520c
commit 80b71f410f

View File

@ -8,26 +8,26 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
type namePair struct { type kv struct {
key, value string key, value string
} }
// recvBuffer is an unbounded channel of *namePair. // recvBuffer is an unbounded channel of *kv.
type recvBuffer struct { type recvBuffer struct {
c chan *namePair c chan *kv
mu sync.Mutex mu sync.Mutex
stopping bool stopping bool
backlog []*namePair backlog []*kv
} }
func newRecvBuffer() *recvBuffer { func newRecvBuffer() *recvBuffer {
b := &recvBuffer{ b := &recvBuffer{
c: make(chan *namePair, 1), c: make(chan *kv, 1),
} }
return b return b
} }
func (b *recvBuffer) put(r *namePair) { func (b *recvBuffer) put(r *kv) {
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
if b.stopping { if b.stopping {
@ -54,7 +54,7 @@ func (b *recvBuffer) load() {
} }
} }
func (b *recvBuffer) get() <-chan *namePair { func (b *recvBuffer) get() <-chan *kv {
return b.c return b.c
} }
@ -123,7 +123,7 @@ func (nr *etcdNR) Watch(target string) {
if resp.Node.Dir { if resp.Node.Dir {
continue continue
} }
entry := &namePair{key: resp.Node.Key, value: resp.Node.Value} entry := &kv{key: resp.Node.Key, value: resp.Node.Value}
nr.recv.put(entry) nr.recv.put(entry)
} }
} }
@ -131,8 +131,8 @@ func (nr *etcdNR) Watch(target string) {
func (nr *etcdNR) GetUpdate() (string, string) { func (nr *etcdNR) GetUpdate() (string, string) {
select { select {
case i := <-nr.recv.get(): case i := <-nr.recv.get():
nr.recv.load() nr.recv.load()string
// returns key and the corresponding value of the updated namePair // returns key and the corresponding value of the updated kv
return i.key, i.value return i.key, i.value
} }
} }