Skip to content

Commit

Permalink
Put back the w.received variable, code more correct and easier to read
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
  • Loading branch information
kozlovic committed Feb 9, 2022
1 parent cc6c8b1 commit 3ad1952
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kv.go
Expand Up @@ -599,6 +599,7 @@ type watcher struct {
sub *Subscription
initDone bool
initPending uint64
received uint64
}

// Updates returns the interior channel.
Expand Down Expand Up @@ -679,15 +680,14 @@ func (kv *kvs) Watch(keys string, opts ...WatchOpt) (KeyWatcher, error) {
}
// Check if done and initial values.
if !w.initDone {
w.received++
// We set this on the first trip through..
if w.initPending == 0 {
w.initPending = delta
}
if w.initPending == 0 {
if w.received > w.initPending || delta == 0 {
w.initDone = true
w.updates <- nil
} else {
w.initPending--
}
}
}
Expand Down

0 comments on commit 3ad1952

Please sign in to comment.