()
| 80 | } |
| 81 | |
| 82 | func 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 | |
| 124 | func mockWatcher_watchWithProgressNotify() { |
| 125 | fmt.Println(`wresp.IsProgressNotify: true`) |
nothing calls this directly
no test coverage detected
searching dependent graphs…