mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #4687 from gyuho/example
clientv3: add IsProgressNotify with example
This commit is contained in:
commit
104a3bdc01
@ -25,7 +25,7 @@ import (
|
||||
var (
|
||||
dialTimeout = 5 * time.Second
|
||||
requestTimeout = 1 * time.Second
|
||||
endpoints = []string{"localhost:12378", "localhost:22378", "http://localhost:32380"}
|
||||
endpoints = []string{"localhost:2378", "localhost:22378", "http://localhost:32380"}
|
||||
)
|
||||
|
||||
func Example() {
|
||||
|
@ -59,3 +59,20 @@ func ExampleWatcher_watchPrefix() {
|
||||
}
|
||||
// PUT "foo1" : "bar"
|
||||
}
|
||||
|
||||
func ExampleWatcher_watchProgressNotify() {
|
||||
cli, err := clientv3.New(clientv3.Config{
|
||||
Endpoints: endpoints,
|
||||
DialTimeout: dialTimeout,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
rch := cli.Watch(context.Background(), "foo", clientv3.WithProgressNotify())
|
||||
wresp := <-rch
|
||||
fmt.Printf("wresp.Header.Revision: %d\n", wresp.Header.Revision)
|
||||
fmt.Println("wresp.IsProgressNotify:", wresp.IsProgressNotify())
|
||||
// wresp.Header.Revision: 0
|
||||
// wresp.IsProgressNotify: true
|
||||
}
|
||||
|
@ -61,6 +61,11 @@ func (wr *WatchResponse) Err() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsProgressNotify returns true if the WatchResponse is progress notification.
|
||||
func (wr *WatchResponse) IsProgressNotify() bool {
|
||||
return len(wr.Events) == 0 && !wr.Canceled
|
||||
}
|
||||
|
||||
// watcher implements the Watcher interface
|
||||
type watcher struct {
|
||||
c *Client
|
||||
|
Loading…
x
Reference in New Issue
Block a user