Browse Source

contrib/recipes: replace WatchPrefix with Watch

Gyu-Ho Lee 9 years ago
parent
commit
8f7948641c
2 changed files with 3 additions and 2 deletions
  1. 1 0
      clientv3/watch.go
  2. 2 2
      contrib/recipes/watch.go

+ 1 - 0
clientv3/watch.go

@@ -31,6 +31,7 @@ type Watcher interface {
 	// through the returned channel.
 	// through the returned channel.
 	// If the watch is slow or the required rev is compacted, the watch request
 	// If the watch is slow or the required rev is compacted, the watch request
 	// might be canceled from the server-side and the chan will be closed.
 	// might be canceled from the server-side and the chan will be closed.
+	// 'opts' can be: 'WithRev' and/or 'WitchPrefix'.
 	Watch(ctx context.Context, key string, opts ...OpOption) WatchChan
 	Watch(ctx context.Context, key string, opts ...OpOption) WatchChan
 
 
 	// Close closes the watcher and cancels all watch requests.
 	// Close closes the watcher and cancels all watch requests.

+ 2 - 2
contrib/recipes/watch.go

@@ -23,7 +23,7 @@ import (
 // WaitEvents waits on a key until it observes the given events and returns the final one.
 // WaitEvents waits on a key until it observes the given events and returns the final one.
 func WaitEvents(c *clientv3.Client, key string, rev int64, evs []storagepb.Event_EventType) (*storagepb.Event, error) {
 func WaitEvents(c *clientv3.Client, key string, rev int64, evs []storagepb.Event_EventType) (*storagepb.Event, error) {
 	w := clientv3.NewWatcher(c)
 	w := clientv3.NewWatcher(c)
-	wc := w.Watch(context.Background(), key, rev)
+	wc := w.Watch(context.Background(), key, clientv3.WithRev(rev))
 	if wc == nil {
 	if wc == nil {
 		w.Close()
 		w.Close()
 		return nil, ErrNoWatcher
 		return nil, ErrNoWatcher
@@ -33,7 +33,7 @@ func WaitEvents(c *clientv3.Client, key string, rev int64, evs []storagepb.Event
 
 
 func WaitPrefixEvents(c *clientv3.Client, prefix string, rev int64, evs []storagepb.Event_EventType) (*storagepb.Event, error) {
 func WaitPrefixEvents(c *clientv3.Client, prefix string, rev int64, evs []storagepb.Event_EventType) (*storagepb.Event, error) {
 	w := clientv3.NewWatcher(c)
 	w := clientv3.NewWatcher(c)
-	wc := w.WatchPrefix(context.Background(), prefix, rev)
+	wc := w.Watch(context.Background(), prefix, clientv3.WithPrefix(), clientv3.WithRev(rev))
 	if wc == nil {
 	if wc == nil {
 		w.Close()
 		w.Close()
 		return nil, ErrNoWatcher
 		return nil, ErrNoWatcher