MCPcopy
hub / github.com/etcd-io/etcd / ExampleWatcher_watchWithRange

Function ExampleWatcher_watchWithRange

client/v3/example_watch_test.go:82–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80}
81
82func ExampleWatcher_watchWithRange() {
83 forUnitTestsRunInMockedContext(mockWatcher_watchWithRange, func() {
84 cli, err := clientv3.New(clientv3.Config{
85 Endpoints: exampleEndpoints(),
86 DialTimeout: dialTimeout,
87 })
88 if err != nil {
89 log.Fatal(err)
90 }
91 defer cli.Close()
92
93 // watches within ['foo1', 'foo4'), in lexicographical order
94 rch := cli.Watch(context.Background(), "foo1", clientv3.WithRange("foo4"))
95
96 go func() {
97 cli.Put(context.Background(), "foo1", "bar1")
98 cli.Put(context.Background(), "foo5", "bar5")
99 cli.Put(context.Background(), "foo2", "bar2")
100 cli.Put(context.Background(), "foo3", "bar3")
101 }()
102
103 i := 0
104 for wresp := range rch {
105 for _, ev := range wresp.Events {
106 fmt.Printf("%s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value)
107 i++
108 if i == 3 {
109 // After 3 messages we are done.
110 cli.Delete(context.Background(), "foo", clientv3.WithPrefix())
111 cli.Close()
112 return
113 }
114 }
115 }
116 })
117
118 // Output:
119 // PUT "foo1" : "bar1"
120 // PUT "foo2" : "bar2"
121 // PUT "foo3" : "bar3"
122}
123
124func mockWatcher_watchWithProgressNotify() {
125 fmt.Println(`wresp.IsProgressNotify: true`)

Callers

nothing calls this directly

Calls 9

WithRangeMethod · 0.80
WithPrefixMethod · 0.80
exampleEndpointsFunction · 0.70
FatalMethod · 0.65
CloseMethod · 0.65
WatchMethod · 0.65
PutMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…