Closed oliveagle closed 9 years ago
currently the following code is enough func (c *Client) Watch(key string, stop chan bool) <-chan *backend.Response { respChan := make(chan *backend.Response, 0) go func() { for { var resp *goetcd.Response var err error //if c.waitIndex == 0 { // resp, err = c.client.Get(key, false, false) // if err != nil { // respChan <- &backend.Response{nil, err} // time.Sleep(time.Second * 5) // continue // } // c.waitIndex = resp.EtcdIndex // respChan <- &backend.Response{[]byte(resp.Node.Value), nil} //} //resp, err = c.client.Watch(key, c.waitIndex+1, false, nil, stop) resp, err = c.client.Watch(key, 0, false, nil, stop) if err != nil { respChan <- &backend.Response{nil, err} time.Sleep(time.Second * 5) continue } c.waitIndex = resp.Node.ModifiedIndex respChan <- &backend.Response{[]byte(resp.Node.Value), nil} } }() return respChan }