mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
bump(github.com/coreos/go-etcd): c21388f46a08162660f44cc7c7267cc4c66d571e
This commit is contained in:
parent
8dc7dd7ea0
commit
b1f1af82f9
@ -50,25 +50,11 @@ 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 {
|
if stop != nil {
|
||||||
// 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))
|
|
||||||
|
|
||||||
ch := make(chan respAndErr)
|
ch := make(chan respAndErr)
|
||||||
|
|
||||||
if stop != nil {
|
|
||||||
go func() {
|
go func() {
|
||||||
resp, err = c.sendRequest("POST", path.Join("watch", key), v.Encode())
|
resp, err = c.sendWatchRequest(key, sinceIndex)
|
||||||
|
|
||||||
ch <- respAndErr{resp, err}
|
ch <- respAndErr{resp, err}
|
||||||
}()
|
}()
|
||||||
@ -83,15 +69,13 @@ func (c *Client) watchOnce(key string, sinceIndex uint64, stop chan bool) (*stor
|
|||||||
resp, err = nil, errors.New("User stoped watch")
|
resp, err = nil, errors.New("User stoped watch")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resp, err = c.sendRequest("POST", path.Join("watch", key), v.Encode())
|
resp, err = c.sendWatchRequest(key, sinceIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -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++ {
|
||||||
|
@ -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++ {
|
for i:=0; i < 100; i++ {
|
||||||
go t(i, ch, etcd.CreateClient())
|
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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user