Browse Source

fix wait_index

Xiang Li 12 năm trước cách đây
mục cha
commit
2022c4bce6
1 tập tin đã thay đổi với 7 bổ sung5 xóa
  1. 7 5
      file_system/watcher.go

+ 7 - 5
file_system/watcher.go

@@ -13,8 +13,9 @@ type watcherHub struct {
 }
 
 type watcher struct {
-	eventChan chan *Event
-	recursive bool
+	eventChan  chan *Event
+	recursive  bool
+	sinceIndex uint64
 }
 
 func newWatchHub(capacity int) *watcherHub {
@@ -43,8 +44,9 @@ func (wh *watcherHub) watch(prefix string, recursive bool, index uint64) (<-chan
 	}
 
 	w := &watcher{
-		eventChan: eventChan,
-		recursive: recursive,
+		eventChan:  eventChan,
+		recursive:  recursive,
+		sinceIndex: index,
 	}
 
 	l, ok := wh.watchers[prefix]
@@ -85,7 +87,7 @@ func (wh *watcherHub) notifyWithPath(e *Event, path string, force bool) {
 
 			w, _ := curr.Value.(*watcher)
 
-			if w.recursive || force || e.Key == path {
+			if (w.recursive || force || e.Key == path) && e.Index >= w.sinceIndex {
 				w.eventChan <- e
 				l.Remove(curr)
 			} else {