From b1f1af82f95d58837a2692c534798dabfa8d66ad Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Wed, 7 Aug 2013 13:52:22 -0700 Subject: [PATCH] bump(github.com/coreos/go-etcd): c21388f46a08162660f44cc7c7267cc4c66d571e --- .../github.com/coreos/go-etcd/etcd/watch.go | 61 +++++++++---------- .../coreos/go-etcd/examples/mutex/mutex.go | 4 +- .../coreos/go-etcd/examples/speed/speed.go | 8 +-- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/third_party/github.com/coreos/go-etcd/etcd/watch.go b/third_party/github.com/coreos/go-etcd/etcd/watch.go index c583e9ad1..5da5565c6 100644 --- a/third_party/github.com/coreos/go-etcd/etcd/watch.go +++ b/third_party/github.com/coreos/go-etcd/etcd/watch.go @@ -50,46 +50,30 @@ func (c *Client) watchOnce(key string, sinceIndex uint64, stop chan bool) (*stor var resp *http.Response var err error - if sinceIndex == 0 { - // Get request if no index is given - resp, err = c.sendRequest("GET", path.Join("watch", key), "") - - if err != nil { - return nil, err - } - - } else { - - // Post - v := url.Values{} - v.Set("index", fmt.Sprintf("%v", sinceIndex)) - + if stop != nil { ch := make(chan respAndErr) - if stop != nil { - go func() { - resp, err = c.sendRequest("POST", path.Join("watch", key), v.Encode()) + go func() { + resp, err = c.sendWatchRequest(key, sinceIndex) - ch <- respAndErr{resp, err} - }() + ch <- respAndErr{resp, err} + }() - // select at stop or continue to receive - select { + // select at stop or continue to receive + select { - case res := <-ch: - resp, err = res.resp, res.err + case res := <-ch: + resp, err = res.resp, res.err - case <-stop: - resp, err = nil, errors.New("User stoped watch") - } - } else { - resp, err = c.sendRequest("POST", path.Join("watch", key), v.Encode()) - } - - if err != nil { - return nil, err + case <-stop: + resp, err = nil, errors.New("User stoped watch") } + } else { + resp, err = c.sendWatchRequest(key, sinceIndex) + } + if err != nil { + return nil, err } b, err := ioutil.ReadAll(resp.Body) @@ -115,3 +99,16 @@ func (c *Client) watchOnce(key string, sinceIndex uint64, stop chan bool) (*stor return &result, nil } + +func (c *Client) sendWatchRequest(key string, sinceIndex uint64) (*http.Response, error) { + if sinceIndex == 0 { + resp, err := c.sendRequest("GET", path.Join("watch", key), "") + return resp, err + } else { + v := url.Values{} + v.Set("index", fmt.Sprintf("%v", sinceIndex)) + resp, err := c.sendRequest("POST", path.Join("watch", key), v.Encode()) + return resp, err + } + +} diff --git a/third_party/github.com/coreos/go-etcd/examples/mutex/mutex.go b/third_party/github.com/coreos/go-etcd/examples/mutex/mutex.go index 90f9b21e5..6b9b24c3e 100644 --- a/third_party/github.com/coreos/go-etcd/examples/mutex/mutex.go +++ b/third_party/github.com/coreos/go-etcd/examples/mutex/mutex.go @@ -14,12 +14,12 @@ func main() { ch := make(chan bool, 10) // set up a lock - c := etcd.CreateClient() + c := etcd.NewClient() c.Set("lock", "unlock", 0) for i := 0; i < 10; i++ { - go t(i, ch, etcd.CreateClient()) + go t(i, ch, etcd.NewClient()) } for i := 0; i < 10; i++ { diff --git a/third_party/github.com/coreos/go-etcd/examples/speed/speed.go b/third_party/github.com/coreos/go-etcd/examples/speed/speed.go index e008a7ca6..97a6e9d02 100644 --- a/third_party/github.com/coreos/go-etcd/examples/speed/speed.go +++ b/third_party/github.com/coreos/go-etcd/examples/speed/speed.go @@ -11,14 +11,14 @@ var count = 0 func main() { ch := make(chan bool, 10) // set up a lock - for i:=0; i < 1000; i++ { - go t(i, ch, etcd.CreateClient()) + for i:=0; i < 100; i++ { + go t(i, ch, etcd.NewClient()) } start := time.Now() - for i:=0; i< 1000; i++ { + for i:=0; i< 100; i++ { <-ch } - fmt.Println(time.Now().Sub(start), ": ", 1000 * 50, "commands") + fmt.Println(time.Now().Sub(start), ": ", 100 * 50, "commands") } func t(num int, ch chan bool, c *etcd.Client) {