Closed microyahoo closed 7 months ago
The PR https://github.com/rosedblabs/rosedb/pull/252/files mainly refactors from the following three aspects.
Add Watcher
interface, the interface mainly refers to etcd WatchStream and watchStream, it contains two methods, Watch
and Close
.
type Watcher interface {
Watch() WatchChan
Close() error
}
The watcher struct implements Watcher interface like follows.
type watcher struct {
queue eventQueue
mu sync.RWMutex
watchCh chan *Event // new added, which is event channels. Watch() will return it.
cond *sync.Cond
capacity uint64 // new added, which is used to record how many events currently, and does not exceed the capacity of the event queue
closeMu sync.Mutex
notifyCh chan struct{} // it is a notification channel, which means watch channel has been closed.
cancelFunc func() // Close() will invoke it
}
@roseduan
How to reproduce: