Skip to content

Commit 4411687

Browse files
committed
coordinator: add watch function to store interface
1 parent 9c380a0 commit 4411687

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

coordinator/history/aferostore.go

+18
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,21 @@ func (s *AferoStore) CompareAndSwap(key string, oldVal, newVal []byte) error {
5959
}
6060
return s.fs.WriteFile(key, newVal, 0o644)
6161
}
62+
63+
// Watch watches for changes to the value of key.
64+
func (s *AferoStore) Watch(_ string) (Watcher, error) {
65+
return &AferoStoreWatcher{}, nil
66+
}
67+
68+
// AferoStoreWatcher implements the Watcher interface for AferoStore.
69+
type AferoStoreWatcher struct{}
70+
71+
// Stop is a no-op for AferoStoreWatcher.
72+
func (w *AferoStoreWatcher) Stop() {
73+
// No-op.
74+
}
75+
76+
// ResultChan returns a nil channel.
77+
func (w *AferoStoreWatcher) ResultChan() <-chan []byte {
78+
return nil
79+
}

coordinator/history/history.go

+14
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,18 @@ type Store interface {
251251
// If the current value is not equal to oldVal, an error must be returned. The comparison must
252252
// treat a nil slice the same as an empty slice.
253253
CompareAndSwap(key string, oldVal, newVal []byte) error
254+
255+
// Watch watches for changes to the value of key.
256+
//
257+
// If the value of key changes, the new value is sent on the channel.
258+
Watch(key string) (Watcher, error)
259+
}
260+
261+
// Watcher watches and reports changes to a key in a Store.
262+
type Watcher interface {
263+
// Stop watching the key and close the result channel.
264+
Stop()
265+
266+
// ResultChan returns a channel which will receive the new value of the key when it changes.
267+
ResultChan() <-chan []byte
254268
}

0 commit comments

Comments
 (0)