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

release-0.4
Brandon Philips 2013-08-07 13:52:22 -07:00
parent 8dc7dd7ea0
commit b1f1af82f9
3 changed files with 35 additions and 38 deletions

View File

@ -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
}
}

View File

@ -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++ {

View File

@ -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) {