Browse Source

bump(github.com/coreos/go-etcd): c21388f46a08162660f44cc7c7267cc4c66d571e

Brandon Philips 12 years ago
parent
commit
b1f1af82f9

+ 29 - 32
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 resp *http.Response
 	var err error
 	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)
 		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 <-stop:
-				resp, err = nil, errors.New("User stoped watch")
-			}
-		} else {
-			resp, err = c.sendRequest("POST", path.Join("watch", key), v.Encode())
-		}
+		case res := <-ch:
+			resp, err = res.resp, res.err
 
 
-		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)
 	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
 	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
+	}
+
+}

+ 2 - 2
third_party/github.com/coreos/go-etcd/examples/mutex/mutex.go

@@ -14,12 +14,12 @@ func main() {
 
 
 	ch := make(chan bool, 10)
 	ch := make(chan bool, 10)
 	// set up a lock
 	// set up a lock
-	c := etcd.CreateClient()
+	c := etcd.NewClient()
 	c.Set("lock", "unlock", 0)
 	c.Set("lock", "unlock", 0)
 
 
 
 
 	for i := 0; i < 10; i++ {
 	for i := 0; i < 10; i++ {
-		go t(i, ch, etcd.CreateClient())
+		go t(i, ch, etcd.NewClient())
 	}
 	}
 
 
 	for i := 0; i < 10; i++ {
 	for i := 0; i < 10; i++ {

+ 4 - 4
third_party/github.com/coreos/go-etcd/examples/speed/speed.go

@@ -11,14 +11,14 @@ var count = 0
 func main() {
 func main() {
 	ch := make(chan bool, 10)
 	ch := make(chan bool, 10)
 	// set up a lock
 	// 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()
 	start := time.Now()
-	for i:=0; i< 1000; i++ {
+	for i:=0; i< 100; i++ {
 		<-ch
 		<-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) {
 func t(num int, ch chan bool, c *etcd.Client) {